我正在为iOS编写一个应用程序,需要同时广告iOS iBeacon和周边服务。必须广告服务而不是仅在周边可发现,因为使用案例要求中央设备(BLE术语)在由于接近iBeacon而被iOS唤醒后(但仍在后台运行)连接到周边设备。在中央设备的后台运行的应用程序只能通过可用服务来发现周边设备,而无法发现所有周边设备[];我的代码可以广告服务或iBeacon,但我还没有找出如何同时进行两者广告的方法。可能iBeacon使用了38字节中的21字节可用空间,导致没有足够的空间广告信标和服务?
这个有效(beacon):
这个有效(beacon):
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,而不是服务:
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 ];
感谢您的查看!