该类不符合Swift中的'CBPeripheralManagerDelegate' [英] Class does not conform to 'CBPeripheralManagerDelegate' in Swift

查看:56
本文介绍了该类不符合Swift中的'CBPeripheralManagerDelegate'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Swift中构建iBeacon发射器,但我无法让我的班采用 CBPeripheralManagerDelegate 协议.

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

在Objective-C中,此协议是初始化PeripheralManager对象所必需的,但是在Swift中,我将收到以下错误消息:

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

class MyBeacon: CBPeripheralManagerDelegate {
    // ...
}

给出错误:

"MyBeacon"不符合"CBPeripheralManagerDelegate"

'MyBeacon' does not conform to 'CBPeripheralManagerDelegate'

由于我的班级未采用该协议,当我尝试使用自动完成初始化PeripheralManager时,也会出现错误

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)

给出错误:

找不到接受提供的参数的'init'的重载

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

任何人都可以阐明一下吗?

Can anyone please shed some light?

推荐答案

您必须实现此方法,因为此方法不是可选的,并且如果确认 CBPeripheralManagerDelegate

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

请参考文档

CBPeripheralManager对象的委托必须采用CBPeripheralManagerDelegate协议,该协议包括众多可选方法和一个必需方法.该协议的必需的方法,它指示外围设备管理器是否可用,在外围设备管理器的状态更新时被调用.

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.

这篇关于该类不符合Swift中的'CBPeripheralManagerDelegate'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆