zoukankan      html  css  js  c++  java
  • 查看 ios 真机调试log,导出log

    使用Xcode 在模拟器李敏运行的时候,可以直接通过xcode 查看log,但是真机测试的时候,xcode 却无法获取到,对于日志输出,可以先保存到真机上,之后通过iTunes 导出即可

    1. 修改源码

      
           此函数要在
          - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
          中调用,这个函数在AppDelegate.m中实现的。
      
      
        // 将NSlog打印信息保存到Document目录下的文件中
      - (void)redirectNSlogToDocumentFolder
      {
          NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
          NSString *documentDirectory = [paths objectAtIndex:0];
          NSString *fileName = [NSString stringWithFormat:@"dr.log"];// 注意不是NSData!
          NSString *logFilePath = [documentDirectory stringByAppendingPathComponent:fileName];
          // 先删除已经存在的文件
          NSFileManager *defaultManager = [NSFileManager defaultManager];
          [defaultManager removeItemAtPath:logFilePath error:nil];
      
          // 将log输入到文件
          freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);
          freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);
      }
      
      
      
             /*******************************************************************************/
      // 当真机连接Mac调试的时候把这些注释掉,否则log只会输入到文件中,而不能从xcode的监视器中看到。
          // 如果是真机就保存到Document目录下的drm.log文件中
          UIDevice *device = [UIDevice currentDevice];
          if (![[device model] isEqualToString:@"iPad Simulator"]) {
              // 开始保存日志文件
              [self redirectNSlogToDocumentFolder];
          }
      /*******************************************************************************/

      修改AppDelegate.m ,添加如上,这样设置log的输出位置,或在xcode的监视器,或者在真机上的文件中

    2. 修改配置文件
      修改项目下的Info.plist , 添加UIFileSharingEnabled键,并将键值设置为YES,添加之后,
      添加之后会变成 Application supports iTunes file sharing YES
      这里写图片描述

    3. 连接真机设备,连接iTunes,导出log 即可
      连接真机设备之后,从应用程序里面找到dr.log 然后导出就可以了
      这里写图片描述

    可以参考:
    http://www.cnblogs.com/ThankForYou/archive/2012/09/12/2681739.html

    http://www.cnblogs.com/ThankForYou/archive/2012/09/12/2681739.html

  • 相关阅读:
    (转)C#中Thread.sleep()
    ZigBee无线信道组成
    JSP应用html乱码的终极解决办法
    How to size text using ems
    iframe和frame的区别
    [洛谷P2827]蚯蚓
    [洛谷P3391]【模板】文艺平衡树(Splay)
    [洛谷P4180]严格次小生成树
    HTTP 常见鉴权
    使用 rsync 备份/复制 系统
  • 原文地址:https://www.cnblogs.com/xinleishare/p/4572333.html
Copyright © 2011-2022 走看看