During the lifetime of my application, I add and remove several times a service but it seems that the number of creation/deletion is limited.
Here is my example (short version). I create a service, i add it in the data base and in the callback i delete it and re-add it, and so on...
@interface ViewController () <CBPeripheralManagerDelegate>
@property(strong,nonatomic) CBPeripheralManager *manager;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_manager = [[CBPeripheralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)addService
{
CBMutableCharacteristic *currentTimeCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:@"AAAA"]
properties:CBCharacteristicPropertyNotify+CBCharacteristicPropertyRead
value:nil
permissions:CBAttributePermissionsReadable];
CBMutableService *currentTimeService = [[CBMutableService alloc] initWithType:[CBUUID UUIDWithString:@"1111"] primary:YES];
currentTimeService.characteristics = @[currentTimeCharacteristic];
NSLog(@"add service request");
[_manager addService:currentTimeService];
}
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral
{
if(peripheral.state == CBPeripheralManagerStatePoweredOn) {
[self addService];
}
}
- (void)peripheralManager:(CBPeripheralManager *)peripheral didAddService:(CBService *)service error:(NSError *)error
{
NSLog(@"did add service %@",[error localizedDescription]);
[_manager removeAllServices];
[self addService];
}
2013-04-15 10:06:26.804 TestBug[1920:907] add service request
2013-04-15 10:06:26.819 TestBug[1920:907] did add service (null)
2013-04-15 10:06:26.821 TestBug[1920:907] add service request
2013-04-15 10:06:26.826 TestBug[1920:907] did add service (null)
2013-04-15 10:06:26.828 TestBug[1920:907] add service request
2013-04-15 10:06:26.833 TestBug[1920:907] did add service (null)
2013-04-15 10:06:26.836 TestBug[1920:907] add service request
2013-04-15 10:06:26.839 TestBug[1920:907] did add service (null)
2013-04-15 10:06:26.842 TestBug[1920:907] add service request
2013-04-15 10:06:26.845 TestBug[1920:907] did add service (null)
2013-04-15 10:06:26.847 TestBug[1920:907] add service request
2013-04-15 10:06:26.850 TestBug[1920:907] did add service (null)
2013-04-15 10:06:26.853 TestBug[1920:907] add service request