didDiscoverPeripheral“构建失败”错误

2023-12-20

我不确定为什么这段代码无法构建,并且错误消息似乎相当神秘。

Code:

var centralManager: CBCentralManager!;
var nrf8001Peripheral: CBPeripheral!;

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    // initialize centralManager
    self.centralManager = CBCentralManager(delegate: self, queue: nil);

    // start scanning for device
    self.centralManager.scanForPeripheralsWithServices([UART_SERVICE_UUID], options:nil);
}

func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData advertisementData: [NSObject : AnyObject]!, RSSI RSSI: NSNumber) {

            //print out the name of the scanned peripheral
            print("Discovered \(peripheral.name)")

            //print out the UUID of the scanned peripheral
            print("NSUUID string \(peripheral.identifier.UUIDString)")

            //stop scanning when found
            self.centralManager.stopScan()

            //connect when found
            self.centralManager.connectPeripheral(peripheral, options:nil);
}

我从 XCode 编译器收到的错误是:

“Objective-C 方法 'centralManager:didDiscoverPeripheral:advertisementData:RSSI:' 由方法 'centralManager(:didDiscoverPeripheral:advertisementData:RSSI:)' 与可选要求方法 'centralManager(协议“CBCentralManagerDelegate”中的:didDiscoverPeripheral:advertisementData:RSSI :)'”

通过查看 CoreBluetooth 文档,似乎方法语法和参数是正确的,并且参数的可选性是直接从规格表复制的:https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CBCentralManagerDelegate_Protocol/#//apple_ref/occ/intfm/CBCentralManagerDelegate/centralManager:didDiscoverPeripheral:advertisementData:RSSI https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CBCentralManagerDelegate_Protocol/#//apple_ref/occ/intfm/CBCentralManagerDelegate/centralManager:didDiscoverPeripheral:advertisementData:RSSI:

任何帮助,将不胜感激!谢谢

根据评论:

  1. 使用 XCode 7 测试版
  2. 当我将函数声明更改为:

    funccentralManager(中央:CBCentralManager,didDiscoverPeripheral外围设备:CBPeripheral,advertisementDataadvertisementData:[NSObject:AnyObject],RSSI RSSI:NSNumber)

我仍然遇到相同的构建错误。

  1. 我的centralManagerDidUpdateState:方法是

    func centralManagerDidUpdateState(central: CBCentralManager) {
    
    print("centralManagerDidUpdateState:");
    
    switch (central.state) {
    
        case .PoweredOff:
            print("CBCentralManagerStatePoweredOff");
    
        case .Resetting:
            print("CBCentralManagerStateResetting");
    
        case .PoweredOn:
            print("CBCentralManagerStatePoweredOn");
    
        //scan for peripheral devices
        self.centralManager.scanForPeripheralsWithServices([UART_SERVICE_UUID], options:nil);
    
        case .Unauthorized:
            print("CBCentralManagerStateUnauthorized");
    
        case .Unsupported:
            print("CBCentralManagerStateUnsupported");
    
        default:
            print("CBCentralManagerStateUnknown");
        }
    }
    

感谢你的建议;我最终通过 XCode 7 文档找到了答案。以下函数的 XCode 6 语法如下:

func centralManagerDidUpdateState(central: CBCentralManager!) {}

func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData advertisementData: [NSObject : AnyObject]!, RSSI RSSI: NSNumber) {}

func centralManager(central: CBCentralManager!, didConnectPeripheral peripheral: CBPeripheral!) {}

func centralManager(central: CBCentralManager!, didDisconnectPeripheral peripheral: CBPeripheral!, error: NSError!) {}

func peripheral(peripheral: CBPeripheral!, didDiscoverServices error: NSError!) {}

func peripheral(peripheral: CBPeripheral!, didDiscoverCharacteristicsForService service: CBService!, error: NSError!) {}

func peripheral(peripheral: CBPeripheral!, didUpdateNotificationStateForCharacteristic characteristic: CBCharacteristic!, error: NSError!) {}

func peripheral(peripheral: CBPeripheral!, didUpdateValueForCharacteristic characteristic: CBCharacteristic!, error: NSError!) {}

但是,这些函数将与 XCode 7 CoreBluetooth 库声明冲突。

注意不同用途选项数据类型.

(XCode 6) error:NSError! vs. (XCode 7) error:NSError?

(XCode 6) advertisementData : [NSObject : AnyObject]! vs. (XCode 7) advertisementData [String : AnyObject]

XCode 7 beta 的相应函数声明实际上如下:

func centralManagerDidUpdateState(central: CBCentralManager) {}

func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {}

func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) {}

func centralManager(central: CBCentralManager, didFailToConnectPeripheral peripheral: CBPeripheral, error: NSError?) {}

func peripheral(peripheral: CBPeripheral, didDiscoverServices error: NSError?) {}

func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) {}

func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) {}

func peripheral(peripheral: CBPeripheral, didUpdateNotificationStateForCharacteristic characteristic: CBCharacteristic, error: NSError?) {}

func centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) {}

希望这对遇到同样问题的其他人有帮助!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

didDiscoverPeripheral“构建失败”错误 的相关文章

随机推荐

  • 对象类型的 Flowtype 数组不允许额外的属性

    我在流程方面遇到了一个奇怪的错误 我只是想有一个函数来接受带有一个对象的数组amount属性 但在提供具有更多属性的对象时出现错误 const sum items Array lt amount number gt gt something
  • Win32Exception 没有足够的存储空间来处理此命令

    通过我的自动崩溃收集MaxTo http www maxto net我收到以下崩溃报告 V8 12 0 0 System ComponentModel Win32Exception Void UpdateLayered 0 Version
  • 使用 less 将 css 文件导入为块级导入

    有没有办法通过使用将 css 文件的规则嵌套在选择器下 import就像导入 less 文件时一样吗 如果你有一个文件 x less x color 000 和文件 main less scope import x less 编译 main
  • NTFS $MFT 文件可以有子记录吗?

    我正在编写一些代码来解析 NTFS 卷中磁盘上的 MFT 这很简单 但一个特殊的极端情况引起了我的注意 我在互联网上的任何地方都找不到明确的答案 对于 NTFS 中的普通文件 如果文件具有的属性多于单个记录所能容纳的属性 则单个文件可能有多
  • 自动展开并输出C/C++代码

    我正在做一个实验 第一步是展开循环 从 C C 十几次 例如 10 50 等 并输出 C C 展开代码 我可以使用任何工具来自动展开此类展开吗 换句话说 我需要的是 C C source loop gt gt TOOL Unroll by
  • 如何通过键选择单个实体(低级java数据存储API)

    我对如何创建 Key 对象来精确选择实体 客户 的 1 行感到有点困惑 我的代码 Query query new Query Customer how do I have to create this key Key key KeyFact
  • AngularJS html5模式和硬404

    我有一个 AngularJS 应用程序正在使用html5mode set to true 目前 该应用程序显示一个软 404 页面 其中 otherwise路由器里设置 有没有一种方法可以在使用 html5 模式时提供实际的 404 HTT
  • `DateTime.Now - DateTimeNow.AddSecond(-1)` 如何为零

    我在控制台应用程序中运行以下代码 while true DateTime dt1 DateTime Now DateTime dt2 DateTime Now AddSeconds 1 if dt1 dt2 Seconds 1 Consol
  • 如何防止在输入字段中输入无效字符

    Onkeydown 我运行以下 JavaScript function ThisOnKeyDown el if el title textonly A Za z s i test el value el value el value rep
  • Python加权随机[重复]

    这个问题在这里已经有答案了 我需要根据加权循环返回不同的值 这样 20 人中有 1 人得到 A 20 人中有 1 人得到 B 其余的人得到 C So A gt 5 B gt 5 C gt 90 这是一个似乎有效的基本版本 import ra
  • 使用EventSource获取用户在线状态可靠吗?

    我使用了 EventSource 方法来获取网站上活跃用户的在线状态 下面的 JavaScript 代码被插入到每个页面中 var source new EventSource set online php 因此这段代码正在执行set on
  • 在 Python 中创建新字典

    我想用 Python 构建一本字典 但是 我看到的所有示例都是从列表实例化字典等 如何在 Python 中创建一个新的空字典 Call dict没有参数 new dict dict 或者简单地写 new dict
  • 裸仓库上的 git diff

    我想看看 gitlab 服务器端上个月 repo 发生了多少变化 cd path to my bare repo git git git dir diff shortstat 1 month ago fatal Unable to read
  • 用于教学的 Python 3 IDE [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 随着 Python 3 的日趋成熟并慢慢获得采用 我们正在尝试在面向 12 18 岁儿童的入门编程课程
  • Bash 循环遍历目录,包括隐藏文件

    我正在寻找一种方法 在 bash 中对我的目录包含的所有内容 即文件 目录和链接 包括隐藏的链接 进行简单循环 如果它可以专门在 bash 中 我会更喜欢 但它必须是最通用的 当然 文件名 和目录名 可以有空格 换行符 符号 除了 和 AS
  • IModelBinder 上的 BindProperty 和 SetProperty 有什么区别

    我正在 Mvc 应用程序中创建自定义模型绑定程序 我想将字符串解析为枚举值并将其分配给模型属性 我已经让它工作了BindProperty方法 但我也注意到有一个SetProperty方法 protected override void Bi
  • PDFBox 按钮执行 javascript 关闭文档

    我的用例是在 pdf 页面上有一个像这样的按钮 实际上是将它们添加到现有页面 但现在我只想看到它对任何东西都有效 Back 它所做的只是关闭当前的 pdf 页面 这个想法是打开多个选项卡 每个选项卡都是一个 pdf 然后当您点击 后退 按钮
  • 从 BigQuery 中的查询返回数组(重复字段)

    我是 BigQuery 和 SQL 的新手 我有一张包含以下详细信息的表格 Schema ID String Nullable BCats String Repeated ID可以重复 Preview ID BCats ABCD BCat2
  • 如何使用美汤进入下一页?

    我必须从网站的 5 个页面中提取信息 每页的末尾都有 下一页 按钮 这是下一个按钮的 html 代码 li class pagination next span class icon arrowright thin pagination b
  • didDiscoverPeripheral“构建失败”错误

    我不确定为什么这段代码无法构建 并且错误消息似乎相当神秘 Code var centralManager CBCentralManager var nrf8001Peripheral CBPeripheral override func v