Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 555
m0s Avatar asked Jul 16 '19 07:07

m0s


2 Answers

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

like image 116
Paulw11 Avatar answered Sep 23 '22 14:09

Paulw11


Please note that Apple changed the CBManager API between 13.0 and 13.1

  • In 13.0 authorization is an instance property.
  • In 13.1 authorization is a type (class) property.

The 13.0 instance property has been marked as deprecated.

like image 27
gabelkonus Avatar answered Sep 24 '22 14:09

gabelkonus