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?
This works (beacon):
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
major:1
minor:1
identifier:@"bentboolean"];
NSMutableDictionary *dict = [[self.beaconRegion peripheralDataWithMeasuredPower:nil] mutableCopy];
[self.peripheralManager startAdvertising:dict ];
This works (service):
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:@[serviceUUID] forKey:CBAdvertisementDataServiceUUIDsKey];
[self.peripheralManager startAdvertising:dict ];
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 ];
Thanks for taking a look!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…