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

5
根据客户需求,当应用程序崩溃时,我希望发送崩溃报告。如何在不崩溃应用的情况下发送崩溃报告?有没有相关链接或文档可以参考?
请告诉我如何实现这一点,否则给我提供相关代码。
谢谢。

如何在没有崩溃的情况下获取崩溃报告!!! ;D - Maulik
1个回答

2

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

下载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]);
}

谢谢提供代码片段。我已经按照您给出的代码进行了操作。现在我遇到了BKAPIClient未声明使用的错误。什么是BKAPIClient?如何解决这个问题?@Maulik - Asokan R
@AsokanR:嗨,这只是一个在我的情况下调用Web服务的类。您只需要编写调用特定Web服务的代码。就这样! - Maulik

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接