Created
August 22, 2014 00:54
-
-
Save jollyjoester/b1c3bd2f3e4c9397f99b to your computer and use it in GitHub Desktop.
ExceptionHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
| 〜 途中省略 〜 | |
| // エラー追跡用の機能を追加する。 | |
| NSSetUncaughtExceptionHandler(&exceptionHandler); | |
| return YES; | |
| } | |
| // 異常終了を検知した場合に呼び出されるメソッド | |
| void exceptionHandler(NSException *exception) { | |
| // ここで、例外発生時の情報を出力します。 | |
| // NSLog関数でcallStackSymbolsを出力することで、 | |
| // XCODE上で開発している際にも、役立つスタックトレースを取得できるようになります。 | |
| NSLog(@"%@", exception.name); | |
| NSLog(@"%@", exception.reason); | |
| NSLog(@"%@", exception.callStackSymbols); | |
| // ログをUserDefaultsに保存しておく。 | |
| // 次の起動の際に存在チェックすれば、前の起動時に異常終了したことを検知できます。 | |
| NSString *log = [NSString stringWithFormat:@"%@, %@, %@", exception.name, exception.reason, exception.callStackSymbols]; | |
| [[NSUserDefaults standardUserDefaults] setValue:log forKey:@"failLog"]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment