1

我正在开发一个需要与外部设备建立蓝牙连接的应用程序,并且我成功地与外部设备建立了连接。

现在,在下面的 CBPeripheralManager 委托中,在 iOS 10 中生成错误并在 iOS 9.0 中完美运行

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

    if serviceCharacteristics.keys.contains(service.UUID) {
        guard let characteristics = service.characteristics else { return }

        peripheral.setNotifyValue(true, forCharacteristic: characteristics[0])

}

我在下面的行中收到错误,

peripheral.setNotifyValue(true, forCharacteristic: characteristics[0])

它说 CBPeripheral 没有成员 setNotifyValue。我不明白。我做了一些解决方法,但没有得到任何帮助。

4

2 回答 2

2

你在使用 Swift 3 吗?方法签名已更改setNotifyValue(_:for:),即:

peripheral.setNotifyValue(true, for: characteristics[0])
于 2016-12-09T13:17:42.647 回答
0

你迁移到 swift 3 了吗?新语法使用“for”而不是“forCharacteristic”:

peripheral.setNotifyValue(true, for: characteristics[0])
于 2016-12-09T13:18:04.400 回答