简体   繁体   English

CoreBluetooth:CBPeripheral没有成员setnotifyValue iOS 10.0

[英]CoreBluetooth : CBPeripheral has no member setnotifyValue iOS 10.0

I am working on an app where i need to have a bluetooth connection with external device and i successfully made connection with external device. 我正在开发一个需要与外部设备建立蓝牙连接并且成功与外部设备建立连接的应用程序。

Now, in below CBPeripheralManager delegate generate error in iOS 10 and working perfectly in iOS 9.0 现在,在下面的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])

}

I am getting error in the below line, 我在下面一行中遇到错误,

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

It says that CBPeripheral has no member setNotifyValue. 它说CBPeripheral没有成员setNotifyValue。 I don't get it. 我不明白 I did some workaround but not getting any help. 我做了一些解决方法,但没有得到任何帮助。

Are you using Swift 3? 您正在使用Swift 3吗? The method signature has changed to setNotifyValue(_:for:) , ie: 方法签名已更改setNotifyValue(_:for:) ,即:

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

Did you migrate to swift 3? 您是否迁移到Swift 3? The new syntax uses "for" instead of "forCharacteristic": 新语法使用“ for”而不是“ forCharacteristic”:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM