加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 当应用程序崩溃时,如何将崩溃报告发送到Web服务?

发布时间:2020-12-14 19:13:07 所属栏目:百科 来源:网络整理
导读:根据客户要求,我想在App崩溃时发送崩溃报告. 如何在不崩溃应用程序的情况下发送崩溃报告.是否有任何链接或文档. 请建议我这样做的方法.另外发布我的代码. 谢谢. 解决方法 当用户在崩溃后启动应用程序时,您可以发送崩溃报告. 下载crashManagetLib以阅读崩溃报
根据客户要求,我想在App崩溃时发送崩溃报告.
如何在不崩溃应用程序的情况下发送崩溃报告.是否有任何链接或文档.

请建议我这样做的方法.另外发布我的代码.

谢谢.

解决方法

当用户在崩溃后启动应用程序时,您可以发送崩溃报告.

下载crashManagetLib以阅读崩溃报告.

您可以在didFinishLaunchingWithOptions中编写崩溃读取代码,例如: –

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    [self checkCrash];
}

// To check Crash and attach the crash file to Email
- (void) checkChrash
{
    //code for the application crash report.
    NSFileManager *file = [NSFileManager defaultManager];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *dir = [paths objectAtIndex:0];
    NSString *errorReportPath = [[dir stringByAppendingPathComponent:@"crash_report.plcrash"] retain];

    //Call Crash Manager if apps is crashed
    [[CrashManager sharedInstance] manageCrashes];
    [[CrashManager sharedInstance] setCrashDelegate:self selector:@selector(notifyException:stackTrace:)];

    //Mail Dialog is display if apps is crashed
    NSString* errorReport = [CrashManager sharedInstance].errorReport;

    if ([file fileExistsAtPath:errorReportPath]) 
    {
        if(nil != errorReport)
        {           
            // log out from facebook.
            [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"TOKEN"];

            NSString *crashResponce = [BKAPIClient sendCrashReportByMethod:aCrashReport WithErrorLog:errorReport];
            NSLog(@"%@",crashResponce);
            if ([crashResponce isEqualToString:@"True"])
            {
                NSLog(@"Crash Report has been sent !");
            }

            [file removeItemAtPath:errorReportPath error:nil];          
        }
    }

    [errorReportPath release];  
}

// For stack trace of crash
- (void) notifyException:(NSException*) exception stackTrace:(NSArray*)stackTrace
{
    // Oh no!  We crashed!
    // Time to output some stuff to the console.

    // Note: Any EXC_BAD_ACCESS crashes (such as accessing a deallocated object) will
    // cause the app to close stdout,so you won't see this trace in such a case.

    NSLog(@"Exception:n%@n",exception);

    NSLog(@"Full Trace:n%@n",[[StackTracer sharedInstance] printableTrace:stackTrace]);

    NSArray* intelligentTrace = [[StackTracer sharedInstance] intelligentTrace:stackTrace];
    NSLog(@"Condensed Intelligent Trace:n%@",[[StackTracer sharedInstance] condensedPrintableTrace:intelligentTrace]);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读