【问题标题】:Is it possible to read app specific warning messages?是否可以阅读特定于应用程序的警告消息?
【发布时间】:2015-03-13 14:50:27
【问题描述】:

我想阅读我的应用程序的控制台。我的目标是找到所有这样的消息:

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可能有什么变化?

【问题讨论】:

    标签: ios logging console


    【解决方案1】:

    可以从“syslog.sock”中读取。在 iOS8 下运行的 Github 上有源代码:https://github.com/eswick/ondeviceconsole

    从 iOS7 开始,ASL 不再适用于系统范围的日志,由于沙盒功能的增加,iOS 7+ 应用只能看到自己的日志消息。

    如果您只想查看自己应用的日志,您仍然可以使用 ASL:

     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);
    

    【讨论】:

    • aslresponse_next 和 aslresponse_free 已弃用,应改用 asl_next 和 asl_free。
    猜你喜欢
    • 2017-08-03
    • 2017-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多