Re: CBPeripheralManager add/remove service several times
Sam, I have just tested your Code under iOS 6.0.3 on a 5th generation iPod touch and can confirm that the problem was already there on 6.0.x. Could not find a workaround (tried adding delays between the addService calls, but same behaviour). Creating a new CBPeripheralManager is not recommended by documentation, so the workaround may be to simply not call the method more often than 7 times :-). Etan On 15.04.2013, at 10:26, Alpwise iOS Dev <alpwiseiosdev@alpwise.com> wrote:
Hi,
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]; }
The output is : 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
So, for the last (7th) add request the callback is never call. It's a bug or a limitation from Apple? is there a known workaround?
Thanks,
Sam
_______________________________________________ Do not post admin requests to the list. They will be ignored. Bluetooth-dev mailing list (Bluetooth-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/bluetooth-dev/kissling%40oberon.ch
This email sent to kissling@oberon.ch
_______________________________________________ Do not post admin requests to the list. They will be ignored. Bluetooth-dev mailing list (Bluetooth-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/bluetooth-dev/site_archiver%40lists.... This email sent to site_archiver@lists.apple.com
participants (1)
-
Etan Kissling