Re: How should CBPeripheralManager state changes be handled?
Re: How should CBPeripheralManager state changes be handled?
- Subject: Re: How should CBPeripheralManager state changes be handled?
- From: mihai sardarescu <email@hidden>
- Date: Mon, 15 Feb 2016 13:12:07 +0000 (UTC)
Hi Craig,
I have tested today and there is a part about advertisement from your answer that I do not understand. Here is my code:
switch (_cbPeripheralManager.state) {
case CBPeripheralManagerStatePoweredOn:
[self addAllBleServicesAndStartAdvertising];
break;
case CBPeripheralManagerStatePoweredOff:
[self addAllBleServicesAndStartAdvertising];
break;
case CBPeripheralManagerStateUnknown:
case CBPeripheralManagerStateResetting:
[self removeAllBleServicesAndStopAdvertising];
break;
}
In this code, I start advertising on CBPeripheralManagerStatePoweredOff. I get a call to [-peripheralManagerDidStartAdvertising:error:] with error nil. If I ask _cbPeripheralManager.isAdvertising it returns YES (the state is CBPeripheralManagerStatePoweredOff). Do I need to restart advertising when the peripheral state changes to CBPeripheralManagerStatePoweredOn in this case? Basically, can I rely on the state _cbPeripheralManager.isAdvertising to decide whether or not I should restart advertising, or should I force start advertising when I the state changes to CBPeripheralManagerStatePoweredOn ?
Thank you,
Mihai
On Friday, February 12, 2016 6:27 PM, Craig Dooley <email@hidden> wrote:
HI Mihai,
On Feb 12, 2016, at 8:29 AM, mihai sardarescu <
email@hidden> wrote:
Hi,
We're working on building an iOS application that is supposed to act as a Bluetooth peripheral when the application is in background or suspended. Some of our users are complaining that the iPhone cannot be discovered after the weekend. We think our application may not react correctly to the changes of the state of its CBPeripheralManager.
Our initial strategy was to add the CBServices and to start advertising on first CBPeripheralManagerStatePoweredOn, and to stop advertising on CBPeripheralManagerStatePoweredOff and CBPeripheralManagerStateResetting (this is the common case for the examples we found on the web). This proved to be a bad idea, as sometimes the application stops advertising (take the case when Bluetooth is turned off and then the application is backgrounded). We changed the strategy and we add the CBServices and start advertising on the first CBPeripheralManagerStatePoweredOn or CBPeripheralManagerStatePoweredOff. This seems to be working, but it is something we have not seen in any example on the web. And we're still experiencing some issues when the phone is not found. We have seen a CBPeripheralManagerStateResetting state when this occurred once, but it is very hard to get bluetooth in this test to try and reproduce.
I have a couple of questions (reading the doc did not really help me here):
1. Is it correct to add Bluetooth services and to start advertising on CBPeripheralManagerStatePoweredOff?
Adding services is fine, but advertising will not work unless the power is on.
2. Is there anything specific we should do on CBPeripheralManagerStateResetting?
Wait for the next update (and invalidate any state you had). It will be followed by another state update.
3. Do we need to restart advertising on each CBPeripheralManagerStatePoweredOn?
Yes.
- Craig
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden