Reputation: 7963
I am sending the date from to the peripheral by using the below code.
NSString* alternative = [NSString stringWithFormat:@"hello"];
NSData *dataToSend = [alternative dataUsingEncoding:NSUTF8StringEncoding];
[self.discoveredPeripheral writeValue:dataToSend forCharacteristic:self.discoveredCharacteristics type:CBCharacteristicWriteWithResponse];
While sending called the delegate method.
- (void)peripheral:(CBPeripheral *)iPeripheral didWriteValueForCharacteristic:(CBCharacteristic *)iCharacteristic error:(NSError *)iError {
NSLog(@"didWriteValue characteristic.value: %@ ", iCharacteristic.value);
NSLog(@"Error = %@", iError);
}
But, here I am getting null value.
I can receive in peripheral app also in,
- (void)peripheralManager:(CBPeripheralManager *)iPeripheral didReceiveWriteRequests:(NSArray *)iRequests {
[iPeripheral respondToRequest:[iRequests objectAtIndex:0] withResult:CBATTErrorSuccess];
CBATTRequest *aRequest = iRequests[0];
NSData *aData = aRequest.value;
NSDictionary *aResponse = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:aData options:NSJSONReadingMutableContainers error:nil];
NSLog(@"Received Data = %@", aResponse);
}
receiving result value is same null.
- (void)peripheral:(CBPeripheral *)iPeripheral didWriteValueForCharacteristic:(CBCharacteristic *)iCharacteristic error:(NSError *)iError
The couldn't recognize the issue while sending the data to peripheral. Any answer will help me a lot
Upvotes: 0
Views: 813