NSException
void handleException(NSException *exceptin)
{
NSMutableDictionary *info = [NSMutableDictionary dictionary];
info[@"callStack"] = [exceptin callStackSymbols];
info[@"reason"] = [exceptin reason];
info[@"name"] = [exceptin name];
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [cachePath stringByAppendingPathComponent:@"exception"];
NSDate *date = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"y-MM-dd HH-mm-ss";
NSString *now = [formatter stringFromDate:date];
NSLog(@"%@",now);
NSLog(@"%@",cachePath);
NSString *newFilePath = [filePath stringByAppendingString:now];
[info writeToFile:newFilePath atomically:YES];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSSetUncaughtExceptionHandler(handleException);
return YES;
}
void handleException(NSException *exception)
{
[[UIApplication sharedApplication].delegate performSelector:@selector(handle)];
}
- (void)handle
{
NSLog(@"handle");
UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"哈哈" message:@"傻逼了吧" preferredStyle:UIAlertControllerStyleAlert];
[alertVc addAction:[UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
}]];
UIApplication *app = [UIApplication sharedApplication];
[[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:NSRunLoopCommonModes];
[[NSRunLoop currentRunLoop] run];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSSetUncaughtExceptionHandler(handleException);
return YES;
}