我正在使用CoreBluetooth中央管理器的iOS应用程序。该应用程序按预期工作,直到我更新到xCode 8.此更新强制我将转换管理器的代码从Swift 2.3转换为Swift 3.0。 之后,我收到错误消息'无法将Type'CBManagerState'的值转换为期望的参数类型'CBCentralManagerState',并且我正在搜索答案,但由于更新是新的原因,因此没有任何有用的问题或有关与Swift 3.0或iOS 10.0一起使用的CB蓝牙的文档。如何在转换为Swift 3.0语法后将类型'CBManagerState'的值转换为预期类型'CBCentralManagerState'?
标有星号的行是产生错误的行。
final class BluetoothSerial: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate {
....//some code here from HM10 Bluetooth Serial
var centralManager: CBCentralManager!
var state: CBCentralManagerState { get { return centralManager.state } *
func centralManagerDidUpdateState(_ central: CBCentralManager) {
//note that "didDisconnectPeripheral" won't be called if BLE is turned off while connected
connectedPeripheral = nil
pendingPeripheral = nil
//send it to the delegate
delegate.serialDidChangeState(central.state) *
}
}
任何帮助表示赞赏。 在此先感谢。
你能试图读取文档中关于BLE前面
CBCentralManager
? [docs](https://developer.apple.com/reference/corebluetooth/cbcentralmanagerstate) –第三行中央管理器的类型是什么?并且delegate.serialDidChangeState()期望什么参数类型? –
是的,我阅读文档,这是如何让它在更新之前完美运行的。 centralManager的类型是'CBCentralManager!'。 delegate.serialDidChangeState()的预期参数类型是'CBCentralManagerState'。这是我用来在更新之前使其工作的基本源代码:https://github.com/hoiberg/HM10-BluetoothSerial-iOS Thaaaanks;) – iiiiirev