我注意到,当设备处于后台时与处于后台时相比,BLE 外围设备的发现行为似乎有所不同(在中央端) + 锁定。
有人可以确认这一点或向我指出更多信息/文档吗?
更具体地说——当我的应用程序(中央)转换到后台和主屏幕时,它会继续按预期发现外围设备,但是当我按下 sleep /唤醒按钮并因此锁定设备时,它停止发现我的外围设备。该应用程序没有崩溃或其他任何事情......事实上,当我解锁设备(返回主屏幕)时,它会恢复发现外围设备而无需将其带回前台。我也明白,BLE 在后台时触发频率较低,但就我而言,我在锁定状态下观察了一个多小时,它从未触发发现,但一旦我解锁它就会恢复正常。
我正在寻找一种解决方案,当设备(作为中央设备运行)被锁定时,我也能够在其中发现外围设备。
感谢您的帮助!
-H
更新...
找到一个有趣的帖子并认为我会分享:http://web.archiveorange.com/archive/v/lBeBkjSSTe5jAan6ufTX
尤其是观察结果(Brian Fudge)很有趣...
A scanning device that is locked does not report any iOS peripherals that are also locked.
On some devices, like iPhone 5 and 5S, you only need to press the home button on the peripheral for the scanner to succeed and peripherals to be reported.
On other devices, like iPad and iPod Touch, you have to press the home button and unlock the peripheral for the scanner to succeed and peripherals to be reported.
A non-iOS device, such as an rMBP, can scan iOS peripherals that are in the background and locked.
All iOS devices can scan hardware peripherals (such as a health tracker) while the iOS device is in the background and locked.
最佳答案
好的,我遇到了同样的问题,并且设法理解了原因。所以基本上当你在后台或设备锁定时,你的应用程序只能发现一次设备(你可以在前台使用标志 CBCentralManagerScanOptionAllowDuplicatesKey 进行多次发现,但它在后台被忽略)
所以我的应用程序在后台时毫无问题地发现了任何 BLE 外围设备,但是一旦我锁定了我的设备,我就无法检测到它们。我发现外设的广播包太大了(发送了2次)。减少我的外围广播数据包似乎可以解决问题。锁定时,iPhone 似乎一次性收听发送的广告包。在前台或后台,它能够监听 2 次发送的数据包。
希望这可以帮助某人。
关于objective-c - CoreBluetooth——在设备锁定时发现 BLE 外围设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20937837/