CoreBluetooth - Writing data from Central to Peripheral

China☆狼群 提交于 2019-12-10 12:13:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!