iOSがcrashログをキャプチャ

1672 ワード

前言app開発の過程で崩壊の問題に直面するのは避けられない.オンライン下の環境では、ブレークポイントを通じて崩壊のコードを見つけることができ、問題の原因を分析することができるが、appが棚に上がった後に使う崩壊情報はどのように統計されているのだろうか.この文書では、オンライン上のクラッシュログ情報を取得する2つの方法について説明します.
方法1:
サードパーティの「友盟統計」を統合することで、オンライン上のクラッシュ・ログを収集します.友盟がここで提供する公式ドキュメントに関するWebサイトは次のとおりです.
http://dev.umeng.com/analytics/ios-doc/integration?spm=0.0.0.0.0bo0PX#5
方法2:
iOS公式sdkはcrashログをキャプチャする方法を提供しています.
1、AppDelegate.mで-(BOOL)アプリケーション:(UIApplication*)アプリケーションdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{//crashログのキャプチャ方法NSSetUncautExceptionHandler(&UncautExceptionHandler);return YES;}
//  crash     :
void UncaughtExceptionHandler(NSException *exception) {
/**
 *          
 */
NSArray *callStack = [exception callStackSymbols];
NSString *reason = [exception reason];
NSString *name = [exception name];
NSString *content = [NSString stringWithFormat:@"========      ========
name:%@
reason:
%@
callStackSymbols:
%@",name,reason,[callStack componentsJoinedByString:@"
"]]; // ① // cotent ② crash // [self sendCrashInfo: content toEmail:@"[email protected]"]; } // crash : - (void)sendCrashInfo:(NSString *)crashString toEmail:(NSString *)email { NSMutableString *mailUrl = [NSMutableString string]; [mailUrl appendString:email]; [mailUrl appendString:@"?subject= "]; [mailUrl appendFormat:@"&body=%@", crashString]; // NSString *mailPath = [mailUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailPath]]; }