问题
I referred Sample app provided by Apple for CoreBluetooth and I succeeded in sending Data from Peripheral to Central, Now I need to write Data from Central to Peripheral. After Googling i found that It can be done using [_discoveredPeripheral writeValue:aData forCharacteristic:charc type:CBCharacteristicWriteWithResponse];
Following is my Implementation of Central, to send Message to peripheral:
-(void)sendMessage:(NSString *)strMessage{
NSData *aData = [strMessage dataUsingEncoding:NSUTF8StringEncoding];
CBMutableCharacteristic *charc =[[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID] properties:CBCharacteristicPropertyWrite value:nil permissions: CBAttributePermissionsWriteable];
[_discoveredPeripheral writeValue:aData forCharacteristic:charc type:CBCharacteristicWriteWithResponse];
}
When I call this method, It is not able to write data, instead of that I can see a CoreBluetooth Warning on console as below,
CoreBluetooth[WARNING] <CBMutableCharacteristic: 0x15e8e420 UUID = 08590F7E-DB05-467E-8757-72F6FAEB13D4, Value = (null), Properties = 0x8, Permissions = 0x2, Descriptors = (null), SubscribedCentrals = (
)> is not a valid characteristic for peripheral <CBPeripheral: 0x15d91250 identifier = 37C314AF-FDB3-1F24-6937-8780B97AAB45, Name = "iPad", state = disconnected>
It would be nice if someone give the best way to get Object of Peripheral and how to initiate sending of data from Central to Peripheral.
EDIT I have tried the way that is shown in How to get the characteristic from UUID in objective-C?
But, In this case I am not able to Loop Services whenever I try for that It returns services=nil.
来源:https://stackoverflow.com/questions/29095333/corebluetooth-writing-data-from-central-to-peripheral