2015-03-13 61 views
1

我想讀我的應用程序的控制檯。我的目標是找到所有消息是這樣的:是否可以閱讀特定於應用程序的警告消息?

Warning: Attempt to present <ChildViewController: 0x7b44e380> on <TopViewController: 0x7a65e5b0> which is already presenting (null) 

我發現在iOS7上你無法讀取系統消息。

Using Objective C to read log messages posted to the device console

In iOS 7 you can use ASL to read messages output by your own app, including on previous runs of the same build of your app, but not messages output by the system or by any other apps. 

對於我的腦海裏任何警告,是一個系統的消息。可能是ios8上的變化?

回答

1

可以從「syslog.sock」中讀取。 Github上的源代碼可以在iOS8下運行:https://github.com/eswick/ondeviceconsole

ASL不再適用於iOS7以上版本的系統範圍日誌,因爲增加了沙箱,iOS 7+應用程序只能看到自己的日誌消息。

如果你只想看你自己的應用程序的日誌,你仍然可以使用翔升:

aslmsg q, m; 
int i; 
const char *key, *val; 
q = asl_new(ASL_TYPE_QUERY); 
aslresponse r = asl_search(NULL, q); 
while (NULL != (m = aslresponse_next(r))) 
{ 
    NSMutableDictionary *tmpDict = [NSMutableDictionary dictionary]; 
    for (i = 0; (NULL != (key = asl_key(m, i))); i++) 
    { 
     NSString *keyString = [NSString stringWithUTF8String:(char *)key]; 
     val = asl_get(m, key); 
     NSString *string = val?[NSString stringWithUTF8String:val]:@""; 
     [tmpDict setObject:string forKey:keyString]; 
    } 
    NSLog(@"%@", tmpDict); 
} 
aslresponse_free(r); 
+0

aslresponse_next&aslresponse_free已過時,應該用asl_next和asl_free代替。 – dortzur 2015-05-18 14:59:29

相關問題