iOS app崩溃收集

本文介绍了多种iOS app崩溃日志收集方法,包括友盟(仅支持OC)、Bugly(支持Swift)、以及iOS自带的崩溃日志收集功能,如通过Xcode的devices查看设备日志、iTunes Connect获取和用户通过iTunes同步分享给开发者。
摘要由CSDN通过智能技术生成

1.  友盟  http://www.umeng.com/ 

     但现在还只支持oc ,不支持swift ,如果是swift代码有问题,捕捉不到问题

   MobClick.setCrashReportEnabled(true)
   MobClick.setLogEnabled(true)
   let version:String = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String
   MobClick.setAppVersion(version)
   MobClick.startWithAppkey("", reportPolicy: REALTIME, channelId: nil)

2. NSSetUncaughtExceptionHandler 也是不支持swift

MyUncaughtExceptionHandler.h :  

#import <Foundation/Foundation.h>

@interface MyUncaughtExceptionHandler : NSObject

+ (void)setDefaultHandler;
+ (NSUncaughtExceptionHandler *)getHandler;
+ (void)TakeException:(NSException *) exception;

@end


MyUncaughtExceptionHandler.m :  

#import "MyUncaughtExceptionHandler.h"

NSString * applicationDocumentsDirectory()
{
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}

void UncaughtExceptionHandler(NSException * exception)
{
    NSArray * arr = [exception callStackSymbols];
    NSString * reason = [exception reason];
    NSString * name = [exception name];
    NSString * url = [NSString stringWithFormat:@"========异常错误报告========\nname:%@\nreason:\n%@\ncallStackSymbols:\n%@",name,reason,[arr componentsJoinedByString:@"\n"]];
    NSString * path = [applicationDocumentsDirectory() stringByAppendingPathComponent:@"Exception.txt"];
    [url writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"%s:%d %@", __FUNCTION__, __LINE__, url);
	//NSString *urlStr = [NSString stringWithFormat:@"mailto:wy@91goal.com?subject=客户端bug报告&body=很抱歉应用出现故障,感谢您的配合!发送这封邮件可协助我们改善此应用<br>"
	//					"错误详情:<br>%@<br>--------------------------<br>%@<br>---------------------<br>%@",
	//					name,reason,[arr componentsJoinedByString:@"<br>"]];
	
	//NSURL *url2 = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
	//[[UIApplication sharedApplication] openURL:url2];
}

@implementation MyUncaughtExceptionHandler

-(NSString *)applicationDocumentsDirectory
{
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}

+ (void)setDefaultHandler
{
    NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
}

+ (NSUncaughtExceptionHandler *)getHandler
{
    return NSGetUncaughtExceptionHandler();
}

+ (void)TakeException:(NSException *)exception
{
    NSArray * arr = [exception callStackSymbols];
    NSString * reason = [exception reason];
    NSString * name = [exception name];
    NSString * url = [NSString stringWithFormat:@"========异常错误报告========\nname:%@\nreason:\n%@\ncallStackSymbols:\n%@",name,reason,[arr componentsJoinedByString:@"\n"]];
    NSString * path = [applicationDocumentsDirectory() stringByAppendingPathComponent:@"Exception.txt"];
    [url writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];

    NSLog(@"%s:%d %@", __FUNCTION__, __LINE__, url);
}

@end

 

在didFinishLaunchingWithOptions方法中:

//        NSSetUncaughtExceptionHandler({
//            ex in
//            print("-------------UncaughtExceptionHandler---------------")
//            print(ex)
//        })
        MyUncaughtExceptionHandler.setDefaultHandler()



3. bugly : 支持swift   http://bugly.qq.com/iosfast#access


4. 漫谈iOS Crash收集框架  http://www.cocoachina.com/ios/20150701/12301.html


5 iOS自带的崩溃日志bug收集功能  :a . 从xcode找到devices 选项中的view devices logs

                                                          b.  应用提交到app store后可从 iTunes Connect 获取

                                                          c. 请用户将设备与电脑上的iTunes Store同步后,系统会将崩溃日志保存在电脑上,让用户email发送给开发者


    参考文档(案例分析): http://www.cocoachina.com/industry/20130725/6677.html
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值