Kirti Parghi
Kirti Parghi

Reputation: 1152

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.

Upvotes: 1

Views: 787

Answers (2)

davidethell
davidethell

Reputation: 12038

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

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

Upvotes: 0

Lars Blumberg
Lars Blumberg

Reputation: 21451

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

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

Upvotes: 2

Related Questions