Skip to content

Instantly share code, notes, and snippets.

@yimajo
Created July 25, 2012 02:41
Show Gist options
  • Save yimajo/3174070 to your computer and use it in GitHub Desktop.
Save yimajo/3174070 to your computer and use it in GitHub Desktop.
未キャッチの例外をキャッチするメソッドを登録してEXC_BAD_ACCESSを保存する
void uncaughtExceptionHandler(NSException *exception);
void uncaughtExceptionHandler(NSException *exception)
{
NSString *crashReport = [NSString stringWithFormat:@"Crash Name:%@\r\n%@\r\nStack Trace:%@",[exception name], [exception reason], [exception callStackSymbols]];
NSString *crashSection = @"====Crash Report====";
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
[ud setObject:[NSString stringWithFormat:@"%@\r\n%@",crashSection,crashReport] forKey:@"CrashReportText"];
[ud synchronize];
NSLog(@"-- %@",crashReport);
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment