Search code examples
ioscore-bluetooth

Checking CBPeripheralManager.authorizationStatus() now that it is deprecated


CBPeripheralManager.authorizationStatus() and CBPeripheralManagerAuthorizationStatus are deprecated based on apple docs. What is the proper way of checking whether user has granted permission to use bluetooth in background now?

CBPeripheralManagerDelegate has peripheralManagerDidUpdateState but that never returns unauthorized regardless of whether user granted the permission or not, instead it only returns poweredOn or poweredOff


Solution

  • CBCentralManager and CBPeripheralManager inherit from CBManager.

    As of iOS 13, CBManager has an authorization property. You can check this for .allowedAlways.

    You can use if #available(iOS 13.0, *) to conditionally use authorization on iOS 13 and later