In Apple's "BTLE Transfer" sample app, and in a test app that I created, I have observed that if the following is performed multiple times as the app is used:
addService
startAdvertising
stopAdvertising
or even:
addService
startAdvertising
stopAdvertising
removeAllServices
…then at some point (after roughly 3-7 iterations of the above), I will no longer get a call to:
peripheralManager:didAddService:error:
Thus, I have to assume that the service has not been added.
To demonstrate this, using the "BTLE Transfer" sample app, add the following to BTLEPeripheralViewController.m:
- (void) peripheralManager: (CBPeripheralManager*) peripheral didAddService: (CBService*) service error: (NSError*) error;
{
NSLog( @"didAddService" );
}
…then, run the app on a device that supports CPPeripheralManager. In the UI, repeatedly perform these two steps:
1. Click "Peripheral" on the first screen
2. Click "Back" on the second screen
Observe in the console that "didAddService" gets logged for the first fews iterations of the above steps, but will eventually no longer appear:
2013-01-10 08:58:14.855 BTLE Transfer[3733:907] self.peripheralManager powered on.
2013-01-10 08:58:14.869 BTLE Transfer[3733:907] didAddService
2013-01-10 08:58:29.476 BTLE Transfer[3733:907] self.peripheralManager powered on.
2013-01-10 08:58:29.484 BTLE Transfer[3733:907] didAddService
2013-01-10 08:58:39.488 BTLE Transfer[3733:907] self.peripheralManager powered on.
2013-01-10 08:58:39.495 BTLE Transfer[3733:907] didAddService
2013-01-10 08:58:46.962 BTLE Transfer[3733:907] self.peripheralManager powered on.
2013-01-10 08:58:46.966 BTLE Transfer[3733:907] didAddService
2013-01-10 08:58:49.349 BTLE Transfer[3733:907] self.peripheralManager powered on.
2013-01-10 08:58:49.352 BTLE Transfer[3733:907] didAddService
2013-01-10 08:58:52.283 BTLE Transfer[3733:907] self.peripheralManager powered on.
2013-01-10 08:58:52.286 BTLE Transfer[3733:907] didAddService
2013-01-10 08:58:54.387 BTLE Transfer[3733:907] self.peripheralManager powered on.
2013-01-10 08:58:56.358 BTLE Transfer[3733:907] self.peripheralManager powered on.
2013-01-10 09:04:05.075 BTLE Transfer[3733:907] self.peripheralManager powered on.
2013-01-10 09:04:35.662 BTLE Transfer[3733:907] self.peripheralManager powered on.
Should I be able to perform addService as many times as I like?
Allan