简体   繁体   中英

BLE writeValue to peripheral

I am having trouble to write values to a BLE device. I translated this:

NSLog(@"Writing value for characteristic %@", interestingCharacteristic);
    [peripheral writeValue:dataToWrite forCharacteristic:interestingCharacteristic
        type:CBCharacteristicWriteWithResponse];

to Swift:

peripheral.writeValue("Writing value for characteristic", forCharacteristic: interestingCharacteristic, type: CBCharacteristicWriteWithResponse)

But I get the error Use of unresolved identifier 'CBCharacteristicWriteWithResponse'

I am new to iOs programming and tried manyfold ways to make it work but it just wouldn't happen. Can you help me please.

You have combined the NSLog statement and the writeValue method into some sort of bizarre mashup.

What you want is

println("Writing value for characteristic \(interestingCharacteristic)")
peripheral.writeValue(dataToWrite, forCharacteristic:interestingCharacteristic, type: CBCharacteristicWriteType.WithResponse)

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