问题描述
CBPeripheralManager.authorizationStatus()
和 CBPeripheralManagerAuthorizationStatus
。检查用户现在是否已授予在后台使用蓝牙权限的正确方法是什么?
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
具有 peripheralManagerDidUpdateState
,但无论用户是否授予许可,都不会返回未经授权的
,而只会返回 poweredOn
或 poweredOff
CBPeripheralManagerDelegate
has peripheralManagerDidUpdateState
but that never returns unauthorized
regardless of whether user granted the permission or not, instead it only returns poweredOn
or poweredOff
推荐答案
CBCentralManager
和 CBPeripheralManager
继承自。
CBCentralManager
and CBPeripheralManager
inherit from CBManager
.
从iOS 13开始, CBManager
有一个属性。您可以检查 .allowedAlways
。
As of iOS 13, CBManager
has an authorization
property. You can check this for .allowedAlways
.
如果#available(iOS,可以使用 13.0,*)
有条件地在iOS 13及更高版本上使用授权
You can use if #available(iOS 13.0, *)
to conditionally use authorization
on iOS 13 and later
这篇关于现在检查CBPeripheralManager.authorizationStatus(),因为它已被弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!