Xcode 8.0 CBCentralManager Issue

后端 未结 1 2015
Happy的楠姐
Happy的楠姐 2021-01-26 14:45

I recently downloaded Xcode 8.0 and trying to run my previous project which uses core bluetooth.

I have enabled Use Legacy Swift Language Version in bu

1条回答
  •  清酒与你
    2021-01-26 15:01

    The simplest approach is just to use the short-hand reference to the enumeration value:

    func centralManagerDidUpdateState(central: CBCentralManager)
    {
        print("state is \(central.state.rawValue)")
        if (central.state == .PoweredOn)
        {
            self.centralManager?.scanForPeripheralsWithServices([serviceUUID], options: nil)
        }
        else
        {
            // do something like alert the user that ble is not on
        }
    
    }
    

    Now your code will compile without errors or warnings and works correctly on all targets

    0 讨论(0)
提交回复
热议问题