iOS捕获系统异常

// 提交异常Log信息
void UncaughtExceptionHandler(NSException *exception) {
    
    // 异常Log信息
    NSString *errorStr = [NSString stringWithFormat:@"错误详情:%@\n%@\n%@",
                          [exception name], [exception reason], [[exception callStackSymbols] componentsJoinedByString:@"\n"]];
    
    // 提交到服务器
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:device_exception, Host]];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setRequestMethod:@"POST"];
    [request setPostValue:errorStr forKey:@"exception"];
    [request setPostValue:@"1" forKey:@"device"];
    [request startSynchronous];
        
}

// AppDelegate中调用
NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler); //设置异常Log信息的处理

 

posted on 2015-09-17 10:32  rgshio  阅读(176)  评论(0编辑  收藏  举报

导航