我有以下场景:iOS 应用程序(外围)X OSX 应用程序(中央)
- 我用 CBPeripheralManagerOptionRestoreIdentifierKey 实例化我的外设管理器。
- 在我的外围设备的 didFinishLaunchingWithOptions 中,我在使用 UIApplicationLaunchOptionsBluetoothPeripheralsKey 获取外围设备后发送本地通知(不要对它做任何事情)
- 在我的外围设备的 willRestoreState 中,我还触发了一个通知(除此之外不要做任何事情)
如果我的外围应用程序在由于内存压力而被杀死之前仍在后台运行,我会从 OSX 中心收到消息。
在 iOS 应用程序被杀死后,当 OSX 中心发送消息时,上面提到的两个通知都会在 iOS 上通过,但我实际上期待的消息并没有。
我在任何时候都没有对我的 peripheralManager 进行 rentantiated,我应该在哪里以及如何做呢?我的应用程序的整个周期只有一个 peripheralManager。
欢迎任何建议。
更新:
如果这样做
let options: Dictionary = [CBPeripheralManagerOptionRestoreIdentifierKey: "myId"]
peripheralManager = CBPeripheralManager(delegate: self, queue: nil, options: options)
在 willRestoreState 中,我的应用程序只是失去了连接