问题
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
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/57052098/checking-cbperipheralmanager-authorizationstatus-now-that-it-is-deprecated