0

我的应用程序上有两个开关,它们可以将我的应用程序变成外围设备或中央设备(BLE 连接中的两个角色)。当应用程序角色作为外围设备时,我初始化了两个 CBPeripheralManager,一个用于广告 ibeacon,另一个用于 BLE 连接.我想要做的是,当另一个设备角色作为中心进入外围设备的范围时,它可以检测到信标,同时扫描外围设备,然后连接到外围设备。连接建立时,中心发送一些数据到外围。

这是我的问题:

我像这样初始化外围设备:

_peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil]; // for BLE connection
_beaconPeripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
_beaconPeripheralData = [self.beaconRegion peripheralDataWithMeasuredPower:nil];

_beaconPeripheralManager startAdvertising:_beaconPeripheralData;
[_peripheralManager startAdvertising:@{ CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:UUID]] }];

像这样初始化中央:

 NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:UUID];
_beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"com.nikotung.ibeacon"];
[_locationManager startMonitoringForRegion:self.beaconRegion];
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
    [_centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:UUID],[CBUUID UUIDWithString:BEACON_UUID]]
                                            options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }];

如果我同时宣传两个外围设备,在中央一侧,我永远无法发现外围设备(_peripheralManager),而只能发现信标(_beaconPeripheralManager)。代表

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI

从来没有打电话。

但如果我只打开_peripheralManager广告,中央方可以发现它并委托呼叫。

这是否意味着我们不能同时宣传两个外围设备,或者日期大小有限。

CBAdvertisementDataLocalNameKey从Apple的文件中可以看出只有两个密钥CBAdvertisementDataServiceUUIDsKey可以做广告。但我发现其中_beaconPeripheralData包含一个kCBAdvDataAppleBeaconKey让我感到困惑的密钥。

那么,我该怎么做才能让一个应用程序可以宣传两个外围设备并正常工作。

4

2 回答 2

0

结合了信标和外围设备的广告数据,并将其与 1 个外围设备管理器实例一起使用;它似乎适用于 iOS (7.0),但不适用于 OSX (10.9)

于 2014-01-16T05:02:14.200 回答
0

信标外围数据和描述 BLE 服务的外围数据都是NSDictionary ,您可以通过NSMutableDictionary将这两者合二为一,并将所需数据作为一个广播。

于 2014-03-02T19:35:00.860 回答