您的位置:首页 > 移动开发

iOS app崩溃收集

2016-02-17 11:17 369 查看
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收集框架 /article/1316410.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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: