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];
    
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章