CoreBluetooth - data recording from central to peripheral

I mentioned a sample application provided by Apple for CoreBluetooth and I was able to send data from peripheral to center, now I need to write data from center to peripheral. After Googling I found that it can be done using[_discoveredPeripheral writeValue:aData forCharacteristic:charc type:CBCharacteristicWriteWithResponse];

Below is my Central implementation to send a message to the periphery:

-(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 cannot write data, instead I can see a warning on CoreBluetooth in the console as shown 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 could give a better way to get Object Peripheral and how to initiate sending data from Central to Peripheral.

EDIT I tried the way shown in How do I get the characteristic from a UUID in objective-C?

But in this case, I cannot use Loop Services whenever I try to do this. It returns services = nil.

0


source to share





All Articles