问题
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