ios 全局异常捕获,上传服务器

 ios中 xcode  设置全局断点快速定位问题代码所在行, 可以获取异常信息,然后上传服务器,做统计

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    NSSetUncaughtExceptionHandler(&handler);
    
    return YES;
}


void handler(NSException* exception){
    NSArray *arr= [exception callStackSymbols]; //得到当前调用栈信息
    
    NSString* reason= [exception reason]; // 非常重要,奔溃的原因
    NSString* name= [exception name];  // 异常信息
    NSString* result = [NSString stringWithFormat:@"当期调用栈信息:%@\nCrash的原因:%@\n异常类型:%@\n",arr,reason,name];
    NSLog(@"%@",result);
    
}

异常地点: 


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  

       @[][1];
    
}

猜你喜欢

转载自blog.csdn.net/dreams_deng/article/details/106644073
今日推荐