简体   繁体   中英

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

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. I don't get it. I did some workaround but not getting any help.

Are you using Swift 3? The method signature has changed to setNotifyValue(_:for:) , ie:

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

Did you migrate to swift 3? The new syntax uses "for" instead of "forCharacteristic":

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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