wlerl wlerl - 5 months ago 9
iOS Question

CBPeripheralManagerAuthorizationStatusNotDetermined

I had open bluetooth, but I use CBPeripheralManagerAuthorizationStatus to check it ,
CBPeripheralManagerAuthorizationStatus status = [CBPeripheralManager authorizationStatus];

if (CBPeripheralManagerAuthorizationStatusAuthorized == status) {

}else if (CBPeripheralManagerAuthorizationStatusNotDetermined == status) {


}
I found status is
CBPeripheralManagerAuthorizationStatusNotDetermined, not CBPeripheralManagerAuthorizationStatusAuthorized, so I don't know why, I use Xcode is 7.3, and my device is 6sPlus, so, it is because device is 6s series, I use my companion device, sometime also couldn't get bluetooth message, my companion device is 6s, so, I want to get your help, thanks.

Answer

Because the default state for bluetooth in your app is not determined, which means it has not asked for permission yet. You need to do the following to request access.

Objective-C

- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
    switch central.state {
    case CBCentralManagerStateUnknown:
        // Request permission here
        break;
    case CBCentralManagerStatePoweredOn:
        // Bluetooth is ready
        break;
    default:
        // Do other stuff here
    }
}

Swift

func centralManagerDidUpdateState(central: CBCentralManager) {
    switch central.state {
    case .Unknown:
        // Request permission here
    case .PoweredOn:
        // Bluetooth is ready
    default:
        // Do other stuff here
    }
}