0

There are two switches on my app ,they can turn my app into a peripheral or a central(two role in BLE connection).When the app role as a peripheral,I initialize two CBPeripheralManagers, one for advertising ibeacon and the other for BLE connecttion.What I want to do is that when another device role as central enter the peripheral's range ,it can detect the beacon ,in the mean time,it scans the peripheral ,then connect to the peripheral.When connection establish,the central send some data to the peripheral.

Here is my problem:

I init peripheral like this:

_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]] }];

init central like this:

 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 }];

If I advertise the two peripherals at the same time,on the central side ,I can never discovery the peripheral(_peripheralManager) but only the beacon(_beaconPeripheralManager) . Delegate

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

never called.

But if I only turn on the _peripheralManager to advertising ,the central side can discovery it and delegate called.

Does it mean we can't advertising two peripherals at the mean time,or the date size limited.

From Apple's document it says that only two keys CBAdvertisementDataLocalNameKey and CBAdvertisementDataServiceUUIDsKey can be advertised.But I found that the _beaconPeripheralData contain a key kCBAdvDataAppleBeaconKey which confuse me.

So ,what can I do to make an app can advertise two peripherals and work normally.

StRiDeR
  • 170
  • 2
  • 10
NikoTung
  • 101
  • 1
  • 1
  • 10

2 Answers2

0

i combined advertisement data for both beacon and peripheral, and used it with 1 instance of peripheral manager; it seems to work on iOS (7.0), but not on OSX (10.9)

Maxim Volgin
  • 3,957
  • 1
  • 23
  • 38
  • Could you please provide additional information on how you did this? I have tried using a single CBPeripheralManager to advertise both beacon and custom service data by merging the dictionary provided by the Beacon API into my own advertisement dictionary, but it doesn't seem to work. The beacon gets advertised but my service doesn't seem discoverable. – Michael McGuire Apr 21 '14 at 20:27
  • This question indicates what you are saying doesn't work (http://stackoverflow.com/questions/19351856/ios-corebluetooth-ibeacon-advertise-an-ibeacon-and-a-peripheral-service-concu?rq=1). This is the same as my experience. Again... how did you accomplish this? – Michael McGuire Apr 24 '14 at 20:15
0

both beacon peripheral data and the peripheral data to describe your BLE service are NSDictionary, you can combine these two into one through an NSMutableDictionary and broadcast the require data as one.

CSchulz
  • 10,882
  • 11
  • 60
  • 114