该类不符合Swift中的'CBPeripheralManagerDelegate'

编程入门 行业动态 更新时间:2024-10-26 18:29:37
本文介绍了该类不符合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'

本文发布于:2023-11-26 17:35:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634528.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不符合   Swift   CBPeripheralManagerDelegate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!