简体   繁体   English

当后台或手机中的应用处于锁定状态时,iOS BLE外围设备扫描

[英]iOS BLE peripheral scanning when app in background or phone is in lock state

Currently working with an app in which needs countinues background scanning for peripheral. 当前正在与需要对外围设备进行后台扫描的应用一起使用。 We need to allow the duplication key while initialising the scanning for the peripheral. 在初始化外围设备的扫描时,我们需要允许复制密钥。

I had written a sample app for experimenting about this. 我已经编写了一个示例应用程序来对此进行实验。 I have enabled the background capabilities in my app for finite sate running.I found that the number of hits in discover peripheral delegate method is very less when app is background. 我已在我的应用程序中启用了后台功能以实现有限状态运行。我发现,当应用程序为后台时,发现外围代理方法中的命中次数非常少。 Even less when phone is in lock state. 手机处于锁定状态时甚至更少。 And the number of hits is different at different time for same app state. 对于相同的应用状态,命中数在不同时间是不同的。 Also we noted a problem in initiating connection when phone is in lock screen or app is in background. 我们还注意到,当手机处于锁定屏幕或应用程序处于后台时,启动连接时会出现问题。

Is this an expected behaviour? 这是预期的行为吗? Did I miss anything? 我有想念吗?

Any help appreciated. 任何帮助表示赞赏。

The documentation says that: 该文档说:

When your iOS app is in the background or in a suspended state, its Bluetooth related capabilities are affected. 当您的iOS应用处于后台或挂起状态时,其与蓝牙相关的功能会受到影响。 […] Even when you declare one or both of [the background execution modes, certain Bluetooth tasks operate differently while your app is in the background. […]即使您声明了一种或两种[后台执行模式],当您的应用程序在后台运行时,某些蓝牙任务也会以不同的方式运行。 You want to take these differences into account when designing your app. 在设计应用程序时,您需要考虑这些差异。

Even apps that support background processing may be terminated by the system at any time to free up memory for the current foreground app. 系统甚至可以随时终止支持后台处理的应用程序,以释放当前前景应用程序的内存。 As of iOS 7, Core Bluetooth supports saving state information for central and peripheral manager objects and restoring that state at app launch time. 从iOS 7开始,Core Bluetooth支持保存中央和外围设备管理器对象的状态信息,并在应用启动时恢复该状态。 You can use this feature to support long-term actions involving Bluetooth devices. 您可以使用此功能来支持涉及蓝牙设备的长期操作。 Source 来源

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. 结果,发现广告外围设备可能需要更长的时间。 Source 来源

Your app is able to scan when in background when declaring it in the plist, but with limited power/performance to save battery, and it can be potentially be killed by the system. 在plist中声明您的应用程序时,它可以在后台扫描,但功率/性能有限,以节省电池,并且可能被系统杀死。

Not sure about it but I think connection is impossible when phone is locked. 不确定,但我认为手机锁定时无法连接。 You can only restore previous connections. 您只能还原以前的连接。

There's more info about background bluetooth operations in here . 在此处有有关背景蓝牙操作的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM