Class does not conform to 'CBPeripheralManagerDelegate' in Swift

被刻印的时光 ゝ 提交于 2021-02-10 07:19:08

问题


I'm trying to build iBeacon emitter in Swift and I cannot get my class to adopt the CBPeripheralManagerDelegate protocol.

This protocol is required in Objective-C for initializing the PeripheralManager object, but in Swift, I will get the following error:

class MyBeacon: CBPeripheralManagerDelegate {
    // ...
}

gives error:

'MyBeacon' does not conform to 'CBPeripheralManagerDelegate'

Since my class is not adopting the protocol, I also get an error when I try to initialize the PeripheralManager using auto complete

self.peripheralManager = CBPeripheralManager(delegate: self, queue: queue)

gives error:

Could not find an overload for 'init' that accepts the supplied arguments

Can anyone please shed some light?


回答1:


You have to implement this method as this method not optional and must be implemented if you confirming CBPeripheralManagerDelegate

func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {

}

write this in class error will go off

refer docs

The delegate of a CBPeripheralManager object must adopt the CBPeripheralManagerDelegate protocol, a protocol consisting of numerous optional methods and one required method.The protocol’s required method, which indicates whether the peripheral manager is available, is called when the peripheral manager’s state is updated.



来源:https://stackoverflow.com/questions/24872187/class-does-not-conform-to-cbperipheralmanagerdelegate-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!