iOS崩溃日志捕获,调试信息。通过电子邮件发送到开发团队 [英] iOS crash log catch, debug info.. Catch and send via email to the Dev team

查看:194
本文介绍了iOS崩溃日志捕获,调试信息。通过电子邮件发送到开发团队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我们遇到一个情况,我们想看到用户在他的设备上的应用程序的调试信息。所以,我正在寻找的是一种在设备上查找日志的方法,将其作为内联文本粘贴到邮件上,并允许用户发送。



有任何想法吗?这里是问题再次..
1)在设备上找到调试日志
2)打开文件,并将文件的内容作为内联文本附加到邮件中。
3)允许用户在下次应用启动时发送电子邮件。



谢谢,

解决方案

感谢所有输入的人..我把你的解决方案分解成一个可以解决我的问题..这是我做的是..当然我没有编译代码,这是一个半烤的代码..但是我会在我的代码中实现一次它会很快一点。



NSLog到文件如何将NSLog转换为文件 LOG2FILE

  #if TARGET_IPHONE_SIMULATOR == 0 
NSArray * paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSString * logPath = [documentsDirectory stringByAppendingPathComponent:@console.log];
freopen([logPath cStringUsingEncoding:NSASCIIStringEncoding],a +,stderr);
#endif

捕获崩溃并将其记录到文件中



首先,创建一个将处理错误并将其输出到控制台的功能(以及您想要使用的任何其他操作):

  void uncaughtExceptionHandler(NSException * exception){
NSLog(@CRASH:%@,exception);
NSLog(@Stack Trace:%@,[exception callStackSymbols]);
//内部错误报告
}

接下来,添加异常处理程序你的应用程序代理:
$ b

   - (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
NSSetUncaughtExceptionHandler(& uncaughtExceptionHandler); //正常发布的东西
}

在info.plist中设置一个变量称为Crashed,然后以这种方式读取/写入

   - (void)readPlist 
{
NSString * localizedPath = [[NSBundle mainBundle] pathForResource:fileName ofType:@plist];
NSMutableDictionary * plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:localizedPath];

NSString *崩溃;
crashed = [plistDict objectForKey:@Crashed];
}


- (void)writeToPlist
{
NSMutableDictionary * plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];

[plistDict setValue:@YESforKey:@Crashed];
[plistDict writeToFile:filePath atomically:YES];
}

应用程序启动后,读取info.plist并提示用户提交崩溃日志..

  {
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc] init ]。
mailComposer.mailComposeDelegate = self; [mailComposer setSubject:@Crash Log];
//设置收件人
NSArray * toRecipients = [NSArray arrayWithObject:@first@example.com];
[mailComposer setToRecipients:toRecipients];
//附加Crash Log ..
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,YES); NSString * documentsDirectory = [paths objectAtIndex:0];
NSString * logPath = [documentsDirectory stringByAppendingPathComponent:@console.log];
NSData * myData = [NSData dataWithContentsOfFile:logPath];
[mailComposer addAttachmentData:myData mimeType:@Text / XMLfileName:@Console.log];
//填写邮件正文文本
NSString * emailBody = @Crash Log;
[mailComposer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
}


Recently we came across a situation where we wanted to see the debug info from the app which a user has on his device. So, what I am looking for is a way to find the log on the device, paste it as inline text on a mail and allow the user to send it..

Any ideas? Here are the questions again.. 1)Find a debug log on the device 2)open the file and attach the contents of the file as inline text in to the mail. 3)Allow the user to email it the next time app launches..

Thanks,

解决方案

Thanks for all the inputs guys.. I clubbed your solutions into one that would solve my problem.. Here is what I made it to be.. Surely I did not compile the code, it is a half baked code.. but I will iron it soon once as I implement it in my code..

NSLog into file How to NSLog into a file LOG2FILE

#if TARGET_IPHONE_SIMULATOR == 0    
    NSArray *paths =  
    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);        
    NSString *documentsDirectory = [paths objectAtIndex:0];    
    NSString *logPath = [documentsDirectory stringByAppendingPathComponent:@"console.log"];    
    freopen([logPath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
#endif

Catch the Crash and Log them too into a File

First, create a function that will handle the error and output it to the console (as well as whatever else you want to do with it):

void uncaughtExceptionHandler(NSException *exception) {    
    NSLog(@"CRASH: %@", exception);      
    NSLog(@"Stack Trace: %@", [exception callStackSymbols]);    
    // Internal error reporting
}

Next, add the exception handler to your app delegate:

-(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:  
(NSDictionary*)launchOptions
{   
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);    // Normal launch stuff
}

Set a variable in the info.plist called Crashed and then read/write it this way

- (void)readPlist
 {
      NSString *localizedPath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"plist"];        
      NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:localizedPath];

    NSString *crashed;
    crashed = [plistDict objectForKey:@"Crashed"];
}


- (void)writeToPlist
{
    NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];

    [plistDict setValue:@"YES" forKey:@"Crashed"];
    [plistDict writeToFile:filePath atomically: YES];
}

Once the app launches read the info.plist and prompt the user to submit the crash logs..

{
    MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
    mailComposer.mailComposeDelegate = self;[mailComposer setSubject:@"Crash Log"];
    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; 
    [mailComposer setToRecipients:toRecipients];
    // Attach the Crash Log..
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,    
    NSUserDomainMask, YES);NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *logPath = [documentsDirectory stringByAppendingPathComponent:@"console.log"];
    NSData *myData = [NSData dataWithContentsOfFile:logPath];
    [mailComposer addAttachmentData:myData mimeType:@"Text/XML" fileName:@"Console.log"];
    // Fill out the email body text
    NSString *emailBody = @"Crash Log";
    [mailComposer setMessageBody:emailBody isHTML:NO];
    [self presentModalViewController:mailComposer animated:YES];
}

这篇关于iOS崩溃日志捕获,调试信息。通过电子邮件发送到开发团队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆