gpt4 book ai didi

iphone - iOS 崩溃日志捕获、调试信息...捕获并通过电子邮件发送给开发团队

转载 作者:IT王子 更新时间:2023-10-29 07:36:50 27 4
gpt4 key购买 nike

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

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

谢谢,

最佳答案

感谢所有输入的人..我将您的解决方案组合成一个可以解决我的问题的解决方案..这就是我做的..当然我没有编译代码,它是半生不熟的代码..但是当我在我的代码中实现它时,我会尽快解决它。

NS登录文件How to NSLog into a file日志文件

#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]);
// Internal error reporting
}

接下来,将异常处理程序添加到您的应用委托(delegate)中:

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

在info.plist中设置一个名为Crashed的变量,然后这样读写

- (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];
}

应用启动后,阅读 info.plist 并提示用户提交崩溃日志。

{
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];
}

关于iphone - iOS 崩溃日志捕获、调试信息...捕获并通过电子邮件发送给开发团队,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8233388/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com