Swift - BLE - 如何添加CBCentralManagerDelegate协议

时间:2014-06-16 14:32:46

标签: swift core-bluetooth

我想制作一个使用蓝牙进行通信的ios应用程序。我正在使用swift。

首先我添加CoreBluetooth.framework,然后添加一个bridge.h并将文件添加到系统桥,导入" CoreBluetooth / CoreBluetooth.h"。

然后我创建一个新类

import UIKit

class BTCentral: NSObject, CBCentralManagerDelegate   {

}

我计划在该课程中创建一个蓝牙CBCentralManager。但是,上面的代码给了我一个错误。

Type 'BTCentral' does not conform to protocol 'CBCentralManagerDelegate' 

以下是特定的ScreenShot:click here

任何帮助将不胜感激!非常感谢你们的时间。

1 个答案:

答案 0 :(得分:13)

您必须实现协议所需的所有方法。在这种情况下,CBCentralManagerDelegate只需要实现一个方法centralManagerDidUpdateState()

将此方法添加到您的班级,错误将消失。

func centralManagerDidUpdateState(central: CBCentralManager!) {

}