Checking CBPeripheralManager.authorizationStatus() now that it is deprecated

ぃ、小莉子 提交于 2020-02-24 12:30:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!