如何以编程方式从iPhone获取iPhone App Crash Log文件

编程入门 行业动态 更新时间:2024-10-28 12:23:54
本文介绍了如何以编程方式从iPhone获取iPhone App Crash Log文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法通过编程方式访问iphone崩溃日志文件。我试图写一个崩溃报告功能,当你在崩溃后启动应用程序时,它会提供将崩溃报告发送到服务器。我找不到如何在应用程序中获取崩溃日志。

Is there a way to access iphone crash log file via programmatically. I trying to write a crash report feature that when you launch the app after a crash, it will offer to send the crash report to the server. I can't find how to get the crash log within the app.

推荐答案

您可以使用以下逻辑。

aslmsg q, m; int i; const char *key, *val; float how_old = fTime ; q = asl_new(ASL_TYPE_QUERY); asl_set_query(q, ASL_KEY_LEVEL, strLoggerLevel ,ASL_QUERY_OP_LESS_EQUAL); asl_set_query(q, ASL_KEY_FACILITY, [@"YourBundleIdOfAPP" UTF8String] ,ASL_QUERY_OP_EQUAL); asl_set_query(q, ASL_KEY_TIME, [[NSString stringWithFormat:@"%.f", [[NSDate date] timeIntervalSince1970] - how_old] UTF8String], ASL_QUERY_OP_GREATER_EQUAL); int goInside=0; aslresponse r = asl_search(NULL, q); while (NULL != (m = aslresponse_next(r))) { NSString *cValueToWrite; NSMutableDictionary *tmpDict = [NSMutableDictionary dictionary]; for (i = 0; (NULL != (key = asl_key(m, i))); i++) { //get the only required fields if(i==12 || i==10 || i==11 || i==8 || i==9 ||i==3) { NSString *keyString = [NSString stringWithUTF8String:(char *)key]; val = asl_get(m, key); NSString *string = [NSString stringWithUTF8String:val]; [tmpDict setObject:string forKey:keyString]; } } cValueToWrite=[[NSString alloc]initWithFormat:@"\n--------------[Debug]----------------\nDateTime: %@\nApplication: %@\nInfo: %@",[tmpDict valueForKey:@"CFLog Local Time"],[tmpDict valueForKey:@"Sender"],[tmpDict valueForKey:@"Message"]]; }

strLoggerLevel 是 NSString ,它包含您想要的记录器类型,其范围最多为7个。

strLoggerLevel is the NSString which holds the logger type which you want which ranges upto 7.

更多推荐

如何以编程方式从iPhone获取iPhone App Crash Log文件

本文发布于:2023-11-27 20:25:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639481.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   文件   iPhone   App   Crash

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!