OGeek|极客世界-中国程序员成长平台

标题: ios - 使ios7 BLE外围设备在后台工作 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:48
标题: ios - 使ios7 BLE外围设备在后台工作

我已阅读有关它的所有相关信息,但仍然无法让我的 iOS7 设备在后台像外围广告商一样工作。它在前台工作正常,但在后台我什至可以发现它。我在 plist 文件中添加了 App 使用 CoreBluetooth 共享数据。我读到进入后台后,它会将我的自定义 UUID 放入溢出数据中。我也试过这个(但没有运气)。

NSDictionary *advertisingData = @{
 CBAdvertisementDataServiceUUIDsKey : @[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID],
 CBAdvertisementDataOverflowServiceUUIDsKey : @[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]
};  
[manager startAdvertising:advertisingData];

在另一边的中央(MAC OS 应用程序),我只扫描我的:TRANSFER_SERVICE_UUID 服务。有什么我错过的东西我应该在中心侧额外实现吗?



Best Answer-推荐答案


请注意 startAdvertising: 方法文档中的这一行:

While an application is in the background, the local name will not be used and all service UUIDs will be placed in the "overflow" area. However, applications that have not specified the "bluetooth-peripheral" background mode will not be able to advertise anything while in the background.

也就是说,后台外围设备会从广告中删除所有内容, iOS 应用程序只能检测到它的存在。 iOS 应用程序能够到达溢出区域,但 MacOS 应用程序不能。您需要在 MacOS 端关闭服务过滤才能检测到外设并连接到它以发现它是否具有搜索到的服务。

仅供引用,这种情况没有解决方法,它已在 Apple bluetooth-dev 邮件列表和许多 SO 问题中讨论过多次。

另请注意,CBAdvertisementDataOverflowServiceUUIDsKey 不是 startAdvertising: 的有效输入键。 CBAdvertisementDataOverflowServiceUUIDsKey 由 iOS 在 didDiscoverPeripheral 回调中返回,如果它在溢出区域中发现了某些东西。仅使用 CBAdvertisementDataServiceUUIDsKey 来定义广告服务列表。

关于ios - 使ios7 BLE外围设备在后台工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20915249/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4