Reputation: 185
My current code is:
@IBAction func sendData(sender: UISwitch) {
if advertisingSwitch.on {
var parameter = NSInteger(45)
let data = NSData(bytes: ¶meter, length: 1)
if let connectedPeripheral = discoveredPeripheral {
println("========= In connected peripheral \(connectedPeripheral)")
//println("========= Send data is \(currentSendData)")
println("========= Characteristic is \(sendDataCharacteristic)")
println("========= data length is \(data.bytes)")
self.sendDataToCentral(connectedPeripheral, characteristic: sendDataCharacteristic!, data: data)
}
}
}
private func sendDataToCentral(peripheral: CBPeripheral, characteristic: CBCharacteristic, data: NSData) {
println("data is \(data)")
peripheral.writeValue(data, forCharacteristic: characteristic, type: CBCharacteristicWriteType.WithoutResponse)
println("writed characteristic \(characteristic)")
}
When I checked the Peripheral, it is connected showing:
BPeripheral: 0x1700ee980, identifier = E2377588-84CB-87ED-570A-B51614287B3C, name = TAv22u-FDF1, state = connected
The characteristic is getting from service scan with known UUID. I am sure the characteristic I got has function "write", which is
<CBCharacteristic: 0x174086090, UUID = FFE9, properties = 0x8, value = (null), notifying = NO>
after I executing function:
peripheral.writeValue(data, forCharacteristic: characteristic, type: CBCharacteristicWriteType.WithoutResponse)
The value in characteristic is not changing. I don't know where did I get wrong.
Upvotes: 1
Views: 5163
Reputation: 2245
peripheral.writeValue(data, forCharacteristic: characteristic, type:
CBCharacteristicWriteType.WithResponse)
try .withResponse
and check what is response from peripheral.
Upvotes: 1