我一直试图设置一个应用程序,使设备扫描外围设备并作为外围设备做广告.目标是当两个设备通过蓝牙发现彼此靠近时在后台唤醒.从Apple文档中,您似乎应该能够在后台运行BLE(启用蓝牙 - 中央和蓝牙 - 外设背景模式),并且当一台设备位于前台时,我的应用程序可以运行.首先,我这样宣传数据:
NSDictionary *advertisingData = @{CBAdvertisementDataLocalNameKey:@"my-peripheral", CBAdvertisementDataServiceUUIDsKey:@[[CBUUID UUIDWithString:identifier]]}; // Start advertising over BLE [peripheralManager startAdvertising:advertisingData];
然后我将设备设置为扫描数据:
NSArray *services = @[[CBUUID UUIDWithString:identifier]]; [centralManager scanForPeripheralsWithServices:services options:nil];
但是,当两者都进入后台(设备必须被锁定)时,蓝牙无法发现和
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
永远不会在任何一个设备上调用 我怎样才能解决这个问题?谢谢