IOS,异常捕获信息上报

void getException(NSException *exception)
{
    NSDictionary *dic = [[NSBundle mainBundle] infoDictionary];
    CFShow((__bridge CFTypeRef)(dic));
    NSString *app_Version = [dic objectForKey:@"CFBundleShortVersionString"];
    
    NSDictionary *dict = @{@"CrashType":exception.name,
                         @"Reason":exception.reason,
                         @"Description":exception.callStackSymbols,
                         @"CodeSegment":@"",
                         @"DeviceType":[[UIDevice currentDevice] model],
                         @"RAM":@"",
                         @"OS":[[UIDevice currentDevice] systemVersion],
                         @"AppVersion":app_Version};
    //存储崩溃信息
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exception.plist"];
    [dict writeToFile:path atomically:YES];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

    NSSetUncaughtExceptionHandler(&getException);
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/exception.plist"];
    if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
        
        NSString *str = [HttpConfig getUrlByMethod:@"AppCrash"];
        NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:path];
        NSLog(@"*******---****%@",dic);
        [ImcNetworkingHelper postDataWithUrl:str dic:dic sucess:^(id opreation) {
            NSLog(@"成功");
            [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
        } dataError:^(NSString *code, NSString *decription) {
            NSLog(@"错误");
        } networkfaile:^(id error) {
            NSLog(@"失败");
        }];
    }

}

你可能感兴趣的:(IOS,异常捕获信息上报)