objective-c - CoreBluetooth——在设备锁定时发现 BLE 外围设备

标签 objective-c background-process core-bluetooth

我注意到,当设备处于后台时与处于后台时相比,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/

相关文章:

objective-c - 单击表行时,Cocoa 绑定(bind) "Selection"不会更改

iOS 13 强制应用显示蓝牙权限提示

swift - 如何在后台广播蓝牙信号,然后在 Swift 中运行前台时发现该设备?

objective-c - objective-c 中的unichar比较

iphone - 在 ios 中制作圆形的 MKMapView?

objective-c - 如何更改某个属性字符串的文本颜色或将其设为粗体?

ruby - Bash - 如何从后台 ruby​​ 脚本获取 STDOUT

ios - 延迟的后台任务有时仅在应用程序返回前台时运行

php - 在后台运行的进程挂起 PHP 页面

objective-c - 命令行工具中的 NSTimer