Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

ios - how to get iPhone App Crash Log file from iPhone programmatically

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the following logic for the same.

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:@"
--------------[Debug]----------------
DateTime: %@
Application: %@
Info: %@",[tmpDict valueForKey:@"CFLog Local Time"],[tmpDict valueForKey:@"Sender"],[tmpDict valueForKey:@"Message"]];
}

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...