简体   繁体   English

即使 iOS 应用程序在后台运行,它也可以充当信标吗?

[英]Can iOS app act as beacon, even when it is running in the background?

I need my app to act as a BLE beacon, even when it is in the background.我需要我的应用程序充当 BLE 信标,即使它在后台。 I've already made the beacon part - works fine when I'm using the app.我已经制作了信标部分 - 当我使用该应用程序时工作正常。

The problem is I've never made anything run in the background before, and not sure what the limitations are - if I will be allowed to let the app act as a beacon in the background.问题是我以前从未在后台运行过任何东西,并且不确定有什么限制-是否允许我让应用程序在后台充当信标。

Was wondering if this is possible or not (both technically, as well according to App Store rules)想知道这是否可能(技术上,以及根据 App Store 规则)

  1. Is this technically possible ?这在技术上可行吗? Can my app act as a beacon, even when the app is not in the foreground.我的应用程序是否可以充当信标,即使该应用程序不在前台。
  2. Is it within App Store rules ?是否符合 App Store 规则?

Unfortunately, iOS apps cannot emit iBeacon advertisements unless they are in the foreground.不幸的是,iOS 应用程序不能发出 iBeacon 广告,除非它们在前台。 If you program your app to advertise iBeacon frames, as soon as the screen turns off or the app is not visible, iOS changes the advertising format to a special generic background advertisement that does not match the iBeacon format.如果您将应用编程为广告 iBeacon 框架,一旦屏幕关闭或应用不可见,iOS 就会将广告格式更改为与 iBeacon 格式不匹配的特殊通用背景广告。

This proprietary background advertisement is useless for identification of a device.这种专有的背景广告对于识别设备是无用的。 It is designed for connection to BLE GATT services from other iOS devices.它专为从其他 iOS 设备连接到 BLE GATT 服务而设计。 Unless you want to advertise a connectable BLE GATT service to other iOS devices this advertisement has little value.除非您想向其他 iOS 设备宣传可连接的 BLE GATT 服务,否则此广告几乎没有价值。 EDIT: There is a way to make use of this advertisement.编辑:有一种方法可以利用这个广告。 See below.见下文。

Apple's documentation describes this limitation here in the section titled "The bluetooth-peripheral Background Execution Mode":苹果的文档描述限制这里在题为“蓝牙外设后台执行模式”的部分:

you should be aware that advertising while your app is in the background operates differently than when your app is in the foreground.您应该知道,当您的应用程序在后台时,广告的运作方式与您的应用程序在前台时的运作方式不同。 In particular, when your app is advertising while in the background:特别是,当您的应用在后台投放广告时:

The CBAdvertisementDataLocalNameKey advertisement key is ignored, and the local name of peripheral is not advertised. CBAdvertisementDataLocalNameKey 广告键被忽略,并且不会广告外设的本地名称。 All service UUIDs contained in the value of the CBAdvertisementDataServiceUUIDsKey advertisement key are placed in a special “overflow” area; CBAdvertisementDataServiceUUIDsKey 广告键的值中包含的所有服务 UUID 都放在一个特殊的“溢出”区域; they can be discovered only by an iOS device that is explicitly scanning for them.它们只能被明确扫描它们的 iOS 设备发现。 If all apps that are advertising are in the background, the frequency at which your peripheral device sends advertising packets may decrease.如果所有正在投放广告的应用程序都在后台,则您的外围设备发送广告数据包的频率可能会降低。

It may not be obvious that the above causes iBeacon transmissions to break, but I assure you that is absolutely a consequence.上述导致 iBeacon 传输中断的原因可能并不明显,但我向您保证这绝对是一个后果。

Read my blog post here for more information on how to put useful beacon data into this background "Overflow Area" advertisement. 在此处阅读我的博客文章,了解有关如何将有用的信标数据放入此背景“溢出区域”广告中的更多信息。

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

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