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(@"失敗");    
                }]; 
       }
}
相關文章
相關標籤/搜索