简体   繁体   English

使ios7 BLE外设在后台工作

[英]Making ios7 BLE peripheral to work in background

I have read every related information about it, but still can't make my iOS7 device work like peripheral advertiser in background. 我已经阅读了所有相关信息,但仍无法使我的iOS7设备在后台像外围广告客户一样工作。 It works fine in foreground, but in background I can even discover it. 它在前景很好,但在后台我什至可以发现它。 I added App shares data using CoreBluetooth in plist file. 我在plist文件中使用CoreBluetooth添加了应用共享数据 I read that after going in background it puts my custom UUID in overflow data. 我读到,进入后台后,它将我的自定义UUID放入溢出数据中。 I tried this one too(but no luck). 我也尝试过这个(但没有运气)。

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

In the central from other side (MAC OS app), I am scanning only for my: TRANSFER_SERVICE_UUID service. 在另一端的中央(MAC OS应用程序),我仅在扫描我的: TRANSFER_SERVICE_UUID服务。 Is there something that I have missed that I should implement additionally in the central side? 有什么我想错过的事情我应该在中央方面另外实施吗?

Note this line from the startAdvertising: method's documentation: 请注意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 . 当应用程序在后台运行时,将不使用本地名称,并且所有服务UUID都将放置在“溢出”区域中 However, applications that have not specified the "bluetooth-peripheral" background mode will not be able to advertise anything while in the background. 但是,未指定“蓝牙外围设备”后台模式的应用程序将无法在后台进行任何广告。

That is, the backgrounded peripheral removes every thing from the advertisement and only its presence can be detected by non iOS applications . 也就是说,背景外围设备会从广告中删除所有内容,并且 iOS应用程序只能检测到它的存在 iOS apps are able to reach the overflow area but MacOS apps can't. iOS应用程序可以到达溢出区域,而MacOS应用程序则不能。 You need to turn off the service filtering on the MacOS side to be able to detect the peripheral and connect to it to discover if it has the searched service. 您需要在MacOS端关闭服务过滤,才能检测外围设备并连接到外围设备,以发现外围设备是否具有搜索到的服务。

FYI, there is no workaround for this scenario, it has been discussed several times on the Apple bluetooth-dev mailing list and in many SO questions. 仅供参考,这种情况没有解决方法,在Apple bluetooth-dev邮件列表和许多SO问题中已经讨论了多次。

Also note that CBAdvertisementDataOverflowServiceUUIDsKey is not a valid input key for startAdvertising: . 另请注意, CBAdvertisementDataOverflowServiceUUIDsKey不是startAdvertising:的有效输入键。 CBAdvertisementDataOverflowServiceUUIDsKey is returned by iOS in the didDiscoverPeripheral callback if it found something in the overflow area. CBAdvertisementDataOverflowServiceUUIDsKey通过iOS版在返回didDiscoverPeripheral回调,如果它发现在溢出区的东西。 Use only CBAdvertisementDataServiceUUIDsKey to define the list of advertised services. 仅使用CBAdvertisementDataServiceUUIDsKey定义播发服务的列表。

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

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