【问题标题】:swift 2.3 how to properly use deprecated CBCentralManagerStateswift 2.3 如何正确使用已弃用的 CBCentralManagerState
【发布时间】:2016-09-02 13:14:45
【问题描述】:

我只是将我的项目转换为 swift 2.3(XCode 8 beta 6),但我不知道如何在旧 iOS 版本上使用枚举 CBManagerState(我的应用具有部署目标 iOS7)。

CBCentralManager 状态现在使用不同的枚举 CBManagerState(之前是 CBCentralManagerState)。

下面的代码无法编译,因为 manager.state 无法与已弃用的枚举 CBCentralManagerState 进行比较,那么我应该将什么放入 else 块中?

感谢您的建议!

func isBluetoothAvailable() -> Bool {
    if #available(iOS 10.0, *) {
        return manager.state == CBManagerState.PoweredOn
    } else {
        return manager.state == CBCentralManagerState.PoweredOn
    }
}

【问题讨论】:

    标签: ios10 xcode8 swift2.3


    【解决方案1】:

    我不知道这是否是一个可靠的解决方案,但删除枚举类型似乎可行...

    func isBluetoothAvailable() -> Bool {
        return manager.state == .PoweredOn
    }
    

    【讨论】:

      猜你喜欢
      • 2020-08-02
      • 1970-01-01
      • 2019-07-12
      • 1970-01-01
      • 1970-01-01
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多