设备锁定时扫描外围设备 [英] Scan for peripherals when device is locked

查看:126
本文介绍了设备锁定时扫描外围设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的中央经理可以在前景和背景中检测到新的外围设备-我知道这是因为我在发现新外围设备时会触发UNNotification.

My central manager can detect new peripherals in the foreground and background - I know this because I trigger a UNNotification when it finds a new peripheral.

但是,当设备被锁定时,它似乎并没有继续扫描新的外围设备.

However, when the device is locked it does not seem to keep scanning for new peripherals.

以我的能力,我启用了使用LE附件以及远程通知的后台模式.我是否缺少BLE的功能,可以让我在设备锁定时检测到新的外围设备?

In my capabilities I have enabled background mode for Using LE accessories, as well as remote notifications. Am I missing something with BLE that can allow me to detect new peripherals when the device is locked?

使用更多信息进行更新:

这是我实例化中央管理器并开始扫描的方式:

central = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey : kRestoreIdKey])
central!.scanForPeripherals(withServices: [kMyService, kMyOtherService], options: [CBCentralManagerScanOptionAllowDuplicatesKey : true])

此处启用了后台模式:

此外,背景模式的plist键:

有什么主意,为什么我的本地通知会在前台或后台扫描时触发,而不是在屏幕锁定时触发?

Any idea why my local notification will trigger when it scans in the foreground or background, but NOT when the screen is locked?

推荐答案

作为蓝牙中心的后台应用程序,您应该能够在设备锁定时继续扫描,但前提是要扫描特定的服务UUID.

As a bluetooth-central background app, you should be able to continue scanning when the device is locked, but only if you are scanning for specific service UUIDs.

已指定蓝牙中心背景模式的应用程序可以在后台扫描.也就是说,它们必须通过在serviceUUIDs参数中指定它们来显式扫描一个或多个服务.在后台扫描时,将忽略CBCentralManager扫描选项.

Apps that have specified the bluetooth-central background mode are allowed to scan while in the background. That said, they must explicitly scan for one or more services by specifying them in the serviceUUIDs parameter. The CBCentralManager scan option is ignored while scanning in the background.

您不能在后台扫描任意设备. (在某些情况下,您可能会放弃它,但这并不意味着它受到支持.)

You cannot scan for arbitrary devices in the background. (It's possible that you get away with it in some cases, but that doesn't mean it's supported.)

也就是说,锁定设备时可以大大增加扫描间隔(因为没有前台应用程序进行扫描,并且系统通常试图通过关闭天线来节省电能).如果您的设备也具有较长的广告间隔(尤其是如果没有建议的广告间隔之一),那么两者之间可能需要很长的时间才能相互发现(请花几分钟而不是几秒钟) ).

That said, the scanning interval can be substantially increased when the device is locked (since there are no foreground apps scanning and the system in general is trying to conserve power by turning off the antenna). If you have a device that also has a long advertising interval (and especially if it doesn't have one of the recommended advertising intervals), then it can take a very long time for the two to discover each other (think minutes, not seconds).

如果所有正在扫描外围设备的应用程序都在后台运行,则中央设备扫描广告包的时间间隔会增加.结果,发现广告外围设备可能需要更长的时间.

If all apps that are scanning for peripherals are in the background, the interval at which your central device scans for advertising packets increases. As a result, it may take longer to discover an advertising peripheral.

建议的广告间隔列表在蓝牙设计指南第3.5节中.

The list of recommended advertising intervals is in Bluetooth Design Guidelines section 3.5.

  • 152.5毫秒
  • 211.25毫秒
  • 318.75毫秒
  • 417.5毫秒
  • 546.25毫秒
  • 760毫秒
  • 852.5毫秒
  • 1022.5毫秒
  • 1285毫秒

关于该主题的有用主题.

这篇关于设备锁定时扫描外围设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆