CBCentralManager iOS10 and iOS9

后端 未结 4 1648
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 21:01

So I\'m migrating to iOS10 but I also need my code to run on iOS9. I\'m using CoreBluetooth and CBCentralManagerDelegate. I can get my code to work for iOS10 however I need

4条回答
  •  遥遥无期
    2021-01-04 21:34

    I worked around this issue on Xcode 8 with Swift 2.3 (targeting iOS 8 and above) by creating an extension property on CBCentralManager which is of the old enum type, CBCentralManagerState. I named it centralManagerState. I refer to CBCentralManager.centralManagerState where I used to refer to CBCentralManager.state.

    extension CBCentralManager {
    
        internal var centralManagerState: CBCentralManagerState  {
            get {
                return CBCentralManagerState(rawValue: state.rawValue) ?? .Unknown
            }
        }
    }
    

    I got the idea from this forum thread though they hadn't posted the code yet.

提交回复
热议问题