问题描述
我正在编写iOS应用程序,要求应用程序同时宣传iOS iBeacon以及广告外围服务。有必要公布该服务,而不是在外设上可以发现,因为用例需要中央(以BLE的说法)在被iOS唤醒(但仍然在后台)后由于接近iBeacon而连接到外围设备。在中央运行的后台运行的应用只能通过可用服务发现外围设备,而不是发现所有外围设备[];我的代码用于宣传服务或iBeacon,但我还没有弄清楚如何同时做两件事。 iBeacon有可能使用21字节的38字节可用空间,而且没有足够的空间来宣传信标和服务?
I'm writing an application for iOS that requires that the application advertise both an iOS iBeacon as well as advertise peripheral service concurrently. It's necessary that the service is advertised rather that simply discoverable on the peripheral because the use case requires the central (in BLE parlance) connect to the peripheral after being woken up by iOS (but still in the background) due to proximity to the iBeacon. Apps running in the background on centrals can only discover peripheral by available service rather than discovering all peripherals [] ; My code works to advertise either the service or the iBeacon but I haven't figured out how to do both at the same time. It's possible that the iBeacon uses 21bytes of the 38bytes of available space and there simply isn't enough space to advertise a beacon as well as a service?
这有效(信标):
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
major:1
minor:1
identifier:@"bentboolean"];
NSMutableDictionary *dict = [[self.beaconRegion peripheralDataWithMeasuredPower:nil] mutableCopy];
[self.peripheralManager startAdvertising:dict ];
此作品(服务):
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:@[serviceUUID] forKey:CBAdvertisementDataServiceUUIDsKey];
[self.peripheralManager startAdvertising:dict ];
将两者加在一起,试图同时宣传这两项服务是行不通的。它只宣传Beacon,而不是服务:
Adding the two together, trying to advertise both services at the same time doesn't work. It only advertises the Beacon, not the service:
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
major:1
minor:1
identifier:@"bentboolean"];
NSMutableDictionary *dict = [[self.beaconRegion peripheralDataWithMeasuredPower:nil] mutableCopy];
[dict setValue:@[serviceUUID] forKey:CBAdvertisementDataServiceUUIDsKey];
[self.peripheralManager startAdvertising:dict ];
感谢您一起来看看!
推荐答案
在我的实践中,iBeacon& BLE服务不能同时做广告。
In my practice, iBeacon & BLE service can not advertise at same time.
如果广告与iBeacon混合,BLE服务无法在前台做广告。
iBeacon无法在后台投放广告。
BLE service can not advertise in foreground if advertise mixed with iBeacon.iBeacon can not advertise in background.
iBeacon& BLE服务可以逐个广告,例如iBeacon宣传0.5秒,然后
BLE服务广告30.0秒。
iBeacon & BLE service can advertise one by one, e.g. iBeacon advertise 0.5 seconds, thenBLE service advertise 30.0 seconds.
希望这会有所帮助
这篇关于iOS CoreBluetooth / iBeacon:同时发布iBeacon和外围服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!