【问题标题】:How to debug or view NSLog output from iOS device where USB is occupied?如何从占用 USB 的 iOS 设备调试或查看 NSLog 输出?
【发布时间】:2013-07-23 14:37:14
【问题描述】:

我正在 iPhone 上开发一个录音机应用程序。为了使用外部 USB 麦克风测试我的应用,我需要从 Mac 上拔下 iPhone,以便连接麦克风。

我的问题是,一旦 iPhone 不再连接到 Mac,我就无法调试我的 iPhone 应用程序,也无法查看控制台输出。有没有办法通过 USB 电缆以外的其他介质连接调试器,例如网络还是蓝牙?

我了解到,在您的 iPhone 越狱后,可以安装 ssh,connect to the iPhone using ssh, and tail the syslog。如果不需要越狱手机,我会立即使用这个解决方案。我不想越狱我想测试我的应用程序的每部手机。

任何用于查看日志输出的非标准但可靠的解决方案也值得赞赏。例如。我目前在 iPhone 上使用快速编写的 HTTP 服务器,然后使用 Mac 上的浏览​​器或 telnet 连接到 iPhone 并查看控制台输出。

【问题讨论】:

标签: iphone ios debugging console


【解决方案1】:

我已经制作了库DVFloatingWindow,可用于直接在应用程序中查看控制台输出。你只需要使用 DVLog 而不是 NSLog:

DVLog(@"Some message %@", parameters);

您还可以通过为每个日志创建单独的选项卡来查看多个日志。按下按钮即可通过电子邮件发送所有日志。

【讨论】:

    【解决方案2】:

    如果您正在寻求实时调试 + 您拥有 iPhone 4,4S 或更旧的 iPad(30 针连接器),也许这可能是您的答案。有了这个配件,您应该能够连接到您的 mac (XCODE) + 到您的外部配件

    http://www.cablejive.com/products/dockStubz.html

    【讨论】:

      【解决方案3】:

      您可以将调试日志写入文件,测试后您可以看到它们。

      @interface LogFile : NSObject
      + (void)WriteLogWithString:(NSString *)log;
      
      @end
      

      这是实现文件

      @implementation LogFile
      
      
      + (NSString*)CurrentSystemTime {
          return [[NSDate date] description];
      }
      
      +(NSString*)getDocumentsPath
      {
          NSString *path  = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
          return path;
      }
      
      + (NSString*)getLogFilePath
      {
          NSString *loggingFilePath = nil;
      
          loggingFilePath = [[self getDocumentsPath] stringByAppendingPathComponent:@"/MYLogFile.txt"];
          return loggingFilePath;
      }
      
      
      + (void)WriteLogWithString:(NSString *)log
      {
      
              if(log != nil){
      
                  NSString *locationFilePath = [self getLogFilePath];
      
                 NSString *str = [NSString stringWithFormat:@"%@  %s [Line %d]: %@", [self CurrentSystemTime],__PRETTY_FUNCTION__,__LINE__,log];            
                  FILE *fp = fopen([locationFilePath UTF8String], "a");
      
                  fprintf(fp,"%s\n", [str UTF8String]);
      
                  fclose(fp);
              }
      
      }
      
      @end
      

      现在你只需要像这样调用方法

       [LogFile WriteLogWithString:@"sachin thakur"];
      

      【讨论】:

      • Thakur sahab 不要忘记启用 iTunes 文件共享密钥。这样就可以使用 iTunes 从设备中提取日志文件
      • @InderKumarRathore 是的 Rathor sahab。
      【解决方案4】:

      当我使用 MFi 时,我有一个 Apple 提供的加密狗,它允许 iPhone 同时连接到计算机和配件。

      您还可以通过设备下方“设备”选项卡中的 Xcode 管理器查看控制台打印输出。

      【讨论】:

        猜你喜欢
        • 2015-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-08
        • 2014-07-24
        • 1970-01-01
        • 2011-04-08
        相关资源
        最近更新 更多