菜鸟教程小白 发表于 2022-12-12 08:54:28

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


                                            <p><p>有没有办法通过编程方式访问 iphone 崩溃日志文件。我试图编写一个崩溃报告功能,当您在崩溃后启动应用程序时,它会提供将崩溃报告发送到服务器。我找不到如何在应用程序中获取崩溃日志。 </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以使用以下逻辑。</p>

<pre><code>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, [@&#34;YourBundleIdOfAPP&#34; UTF8String] ,ASL_QUERY_OP_EQUAL);

asl_set_query(q, ASL_KEY_TIME, [ 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 = ;

    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 = ;
            val = asl_get(m, key);

            NSString *string = ;
            ;
      }
    }

    cValueToWrite=[initWithFormat:@&#34;\n------------------------------\nDateTime: %@\nApplication: %@\nInfo: %@&#34;,,,];
}
</code></pre>

<p><code>strLoggerLevel</code> 是 <code>NSString</code>,它包含您想要的记录器类型,范围高达 7。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何以编程方式从 iPhone 获取 iPhone 应用程序崩溃日志文件,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/22654089/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/22654089/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何以编程方式从 iPhone 获取 iPhone 应用程序崩溃日志文件