集成 iBeacon 和 coreBluetooth 外设

Integrating iBeacon and coreBluetooth peripheral

我想知道是否可以通过 coreBluetooth 将设备作为外围设备和 iBeacons 的范围来宣传服务,并在后台完成这两项工作? 本质上,目的是确定信标的范围,然后如果信标在.Near 或.Immediate 范围内,则更新设备所宣传的服务的特性。 我可以愉快地完成测距任务,虽然我已经找到了关于设备作为外围设备的信息,但我认为我可以管理它,但是由于后台功能限制而反复停止我想知道这种情况之前是否可能我花了很多时间试图完成一些事,但事实证明每个人都知道这是不可能的。总体而言,我是 Swift 和 iOS 的新手,所以我需要时间才能完成很多工作。任何建议将不胜感激。 谢谢

这是可以的,虽然后台有限制。

前景:

  • 您所描述的完全有可能。 iOS 允许使用 CoreBluetooth 同时广播蓝牙 LE 服务,同时使用 CoreLocation.
  • 为 iBeacon 进行测距

背景:

  • iOS 使用 CoreLocation 的信标测距 API 将后台信标扫描 限制为仅 五秒 在第一次检测到信标区域之后。您可以使用博客 post 我写的 here 中的技术将这五秒的扫描时间延长至最多三分钟。延长时间需要为您的 Info.plist 添加位置背景模式,这可能会使您的应用更难获得 AppStore 的批准。

  • iOS 上的后台蓝牙 LE 服务广告 与前台广告不同。它 使用 Apple 专有技术 将服务标识符折叠成一个较小的广告数据包,该数据包在广告蓝牙 LE 服务的所有应用程序之间共享。这些可能不容易被非 iOS 低功耗蓝牙设备发现:

The CBAdvertisementDataLocalNameKey advertisement key is ignored, and the local name of peripheral is not advertised. All service UUIDs contained in the value of the CBAdvertisementDataServiceUUIDsKey advertisement key are placed in a special “overflow” area; they can be discovered only by an iOS device that is explicitly scanning for them. If all apps that are advertising are in the background, the frequency at which your peripheral device sends advertising packets may decrease.

有关详细信息,请参阅蓝牙外设后台执行模式部分here