【问题标题】:Understanding NSLog了解 NSLog
【发布时间】:2015-10-15 07:50:20
【问题描述】:

NSLog 文档说:

将错误消息记录到 Apple 系统日志工具。

这是否意味着如果我想测试我的应用程序在被杀死时会做什么,我可以使用 XCode->Devices 并查看日志?

我正在测试 BLE 状态恢复,据说当特定 BLE 事件发生时,它会在短时间内重新启动应用程序(参见下面的代码)。但是,我无法在设备日志中看到任何消息(见下图)。

我错过了什么吗?如何记录这些事件?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // The system provides the restoration identifiers only for central managers that had active or pending peripheral connections or were scanning for peripherals.
    NSArray * centralManagerIdentifiers = launchOptions[UIApplicationLaunchOptionsBluetoothCentralsKey];

    if (centralManagerIdentifiers != nil) {
        for (int i=0; i<[centralManagerIdentifiers count]; i++) {
            NSString * identifier = [centralManagerIdentifiers objectAtIndex:i];
            NSLog(@"bluetooth central key identifier %@", identifier);

            self.centralManagerDelegates = [BluetoothStatePreservationSync sharedInstance];
        }
    }

    // Override point for customization after application launch.
    return YES;
}

【问题讨论】:

  • 如果您将您的设备连接到“iPhone 配置实用程序”并检查控制台,您还可以在终止应用程序后检查设备日志。我不确定你现在是否可以在新版本的 OSX 上安装它,但你可以试一试。它还会在您的应用程序启动后向您显示 NSLog 消息。 (Device + App NSLog 消息一起)
  • @sneha 我在哪里可以下载这个“iPhone 配置实用程序”?它是官方工具还是第三方工具?
  • 这是苹果的官方工具,但他们停止了版本更新,但它仍然有效。 iphone-configuration-utility.soft32.com

标签: ios xcode nslog


【解决方案1】:

我认为您没有在“centralManagerIdentifiers”中获得任何数据。 (centralManagerIdentifiers 应该为零)。 正因为如此,if 条件没有被执行。

是的,NSLog 肯定会在设备中打印日志。

尝试在 if 条件之外添加测试日志。它肯定会打印在设备日志中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    • 2013-10-24
    • 2014-01-07
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    相关资源
    最近更新 更多