Swift - BTLE - How to Add CBCentralManagerDelegate Protocal

I want to make an ios application using bluetooth for communication. I use fast.

So, first I add CoreBluetooth.framework, then add bridge.h and add the file to the system bridge, importing "CoreBluetooth / CoreBluetooth.h".

Then I create a new class,

import UIKit class BTCentral: NSObject, CBCentralManagerDelegate { } 

I plan to create a bluetooth CBCentralManager in this class. However, the above code gives me an error.

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

Here is a specific ScreenShot: click here

Any help would be appreciated! Thank you guys for your time.

+7
swift core-bluetooth
source share
1 answer

You must implement all the methods required by the protocol. In this case, CBCentralManagerDelegate requires only one method, centralManagerDidUpdateState() .

Add this method to your class and the error will disappear.

 func centralManagerDidUpdateState(central: CBCentralManager!) { } 
+12
source share

All Articles