iOS的7核心蓝牙外设在后台运行 [英] iOS 7 Core Bluetooth Peripheral running in background

查看:368
本文介绍了iOS的7核心蓝牙外设在后台运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的是我的iOS设备是广告蓝牙LE服务的时候,即使当应用程序没有运行,这样我可以有它的另一个iOS设备扫描,找到它。我在这里跟随苹果的一个后台说明:

What I want is for my iOS device to be advertising a Bluetooth LE service all the time, even when the app isn't running, so that I can have another iOS device scan for it and find it. I have followed Apple's backgrounding instructions here:

<一个href=\"https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/PerformingCommonPeripheralRoleTasks/PerformingCommonPeripheralRoleTasks.html#//apple_ref/doc/uid/TP40013257-CH4-SW1\">https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/PerformingCommonPeripheralRoleTasks/PerformingCommonPeripheralRoleTasks.html#//apple_ref/doc/uid/TP40013257-CH4-SW1.

我可以得到它在前台OK,有时在后台做广告,但它不留广告所有的时间。如果您有它安装在后台运行,不应该甚至设备重启后开始投放广告,就像背景位置服务自动启动,重新启动后的工作?是他们的一个后台限制未在苹果的文档中列出(或很难找到)?有谁在后台正确有一个核心的蓝牙外设广告的例子吗?

I can get it to advertise in the foreground ok and sometimes in the background but it doesn't stay advertising all the time. If you have it setup to run in the background, shouldn't it start advertising even after a device restart, just like background location services automatically start working after a restart? Are their limitations to the backgrounding that are not listed (or hard to find) in Apple's docs? Does anyone have an example of a Core Bluetooth Peripheral advertising correctly in the background?

谢谢...

推荐答案

如果您添加蓝牙外设一个后台模式下应用程序的plist中背景广告是可能的。一旦你这样做,你的应用程序将继续接收回调即使后台运行。

Background advertisement is possible if you add the bluetooth-peripheral backgrounding mode to the app's plist. Once you do that, your app will continue to receive the callbacks even if backgrounded.

该广告是一个棘手的野兽苹果实施了多项优化,从而降低功耗,这些只要应用程序是后台运行降低了广告的质量。即:严重的速度下降,不包括对广告的服务和本地名称也不包括在内。一旦应用程序又回到前台,这些限制是无效的。

The advertisement is a tricky beast as Apple implemented several optimizations to reduce the power consumption and these reduce the quality of the advertisement as soon as the app is backgrounded. Namely: the rate is reduced severely, the advertised services are not included and the local name is not included either. Once the app comes back to foreground, these restrictions are invalidated.

在一般情况下,这种后台运行的操作要求将运行的应用程序。与iOS 7的恢复过程已经实现了允许OS同时被终止代表应用程序的行为和恢复应用程序时,某些传输或其他操作迫在眉睫。这需要你恢复键添加到 CBPeripheralManager / CBCentralManager 的初始化选项。启动您的应用程序一次仍然需要,但在那之后,iOS的将继续充当对切牙/外设BLE门面。

In the general case, this kind of backgrounded operation requires the app to be running. With iOS 7 the restoration process has been implemented that allows the OS to act on the app's behalf while it is terminated and restore the app when some transmission or other operation is imminent. This requires you to add the restoration key to the initialization options of the CBPeripheralManager/CBCentralManager. Starting your application once is still required but after that, iOS will continue to act as the BLE facade towards the centrals/peripherals.

更新:我跑了苹果蓝牙开发列表上的循环,以及这个问题,发现蓝牙核心管理人员的宣布为无法重启后恢复。这不是任何文档中描述的,但可能是在WWDC视频提及。我们应该提交一个bug,并复制它来提高苹果的知名度。

UPDATE: I ran a loop on the Apple bluetooth-dev list as well with this question and found that Core Bluetooth managers were declared to be not able to restore after reboot. This is not described in any documentation but probably was mentioned in the WWDC videos. We should file a bug and replicate it to raise Apple's awareness.

这篇关于iOS的7核心蓝牙外设在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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