相关疑难解决方法(0)

核心蓝牙在后台进行广告和扫描

我一直试图设置一个应用程序,使设备扫描外围设备并作为外围设备做广告.目标是当两个设备通过蓝牙发现彼此靠近时在后台唤醒.从Apple文档中,您似乎应该能够在后台运行BLE(启用蓝牙 - 中央和蓝牙 - 外设背景模式),并且当一台设备位于前台时,我的应用程序可以运行.首先,我这样宣传数据:

NSDictionary *advertisingData = @{CBAdvertisementDataLocalNameKey:@"my-peripheral",
                              CBAdvertisementDataServiceUUIDsKey:@[[CBUUID UUIDWithString:identifier]]};

// Start advertising over BLE
[peripheralManager startAdvertising:advertisingData]; 
Run Code Online (Sandbox Code Playgroud)

然后我将设备设置为扫描数据:

NSArray *services = @[[CBUUID UUIDWithString:identifier]];

[centralManager scanForPeripheralsWithServices:services options:nil];
Run Code Online (Sandbox Code Playgroud)

但是,当两者都进入后台(设备必须被锁定)时,蓝牙无法发现和

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
Run Code Online (Sandbox Code Playgroud)

永远不会在任何一个设备上调用 我怎样才能解决这个问题?谢谢

iphone cocoa-touch bluetooth ios core-bluetooth

30
推荐指数
3
解决办法
2万
查看次数

标签 统计

bluetooth ×1

cocoa-touch ×1

core-bluetooth ×1

ios ×1

iphone ×1