Swift:获取蓝牙授权的当前状态

问题描述 投票:0回答:1

我目前正在我的应用程序上实现蓝牙许可。我使用CBManager.authorization获取创作的当前状态,但这仅适用于ios 13.1。这是一个open var class authorization,还有另一个作为var authorization。我无法在iOS 13中呼叫任何一个。

ios swift bluetooth core-bluetooth ios-bluetooth
1个回答
0
投票

您应使用CBCentralManage。创建一个实例:

let manager = CBCentralManage(delegate: self, queue: nil, options: nil)

并使用类似的委托:

func centralManagerDidUpdateState(_ central: CBCentralManager) {
        switch central.state {
        case .unknown: <#code#>
        case .resetting: <#code#>
        case .unsupported: <#code#>
        case .unauthorized: <#code#>
        case .poweredOff: <#code#>
        case .poweredOn: <#code#>
        @unknown default: <#code#>
        }
}

假设您没有忘记更新权限消息的.plist文件

© www.soinside.com 2019 - 2024. All rights reserved.