1
votes

CBCentralManger Delegate method behaves differently in iOS 11 and below iOS 11

Below iOS 11: After updating the CBCentralMangaer state to CBManagerStatePoweredOff state CentralManager delegate -(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error is calling and connected peripheral will get disconnect.

iOS 11 After updating the CBCentralMangaer state to CBManagerStatePoweredOff state central manager disconnect delegate didDisconnectPeripheral is not calling.

I want disconnect delegate should invoked in iOS 11, So How can I resolve this issue in iOS 11.

1
You said the delegate method is being called in iOS 11, which is what you want. Regardless, you cannot change the behaviour of Core Bluetooth, particularly not in an old version of iOS that won't receive any more updates.Paulw11
@Paulw11 Thanks for the catch. Question is updated can you please check it now.user5180348
How do you power off Bluetooth in this case? Are you using the swipe up/down menu or Settings app?Markus Rautopuro

1 Answers

0
votes

You are correct that the API behavior changed between iOS 10 and iOS 11 in regards to bluetooth state changes. Unfortunately there is nothing you can do to change this.

However, the best way to work around this is to add your own logic in the centralManagerDidUpdateState: callback. There you can check if the new state is CBManagerStatePoweredOff and you are running iOS 11 or above. If that is the case then just do whatever you need to do, update UI or similar.

- (void)centralManagerDidUpdateState:(CBCentralManager *)central;
{
    if (central.state == CBManagerStatePoweredOff && @available(iOS 11, *)) 
    {
        // Do the same stuff that you would do in didDisconnectPeripheral: on iOS 10.
    }
}