gpt4 book ai didi

ios - 如何以编程方式从 iPhone 获取 iPhone App 崩溃日志文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:45 25 4
gpt4 key购买 nike

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

最佳答案

您可以使用以下逻辑。

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

strLoggerLevelNSString,它包含您想要的记录器类型,最大范围为 7。

关于ios - 如何以编程方式从 iPhone 获取 iPhone App 崩溃日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22654089/

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