19
我實現的iOS客戶端CoreBluetooth服務器&用於發送數據如何正確實現didReceiveWriteRequests? iOS6的CoreBluetooth
client site
[self.connectedPeripheral writeValue:mainData forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
和
- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic
{
NSString *s= [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding];
NSLog(@"didWriteValue characteristic.value: %@ ", s);
}
和服務器站點
- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests
{
NSData *res= [[NSString stringWithFormat:@"Hello"] dataUsingEncoding:NSUTF8StringEncoding];
[self.peripheral updateValue:res
forCharacteristic:self.writeCharacteristic
onSubscribedCentrals:nil];
[peripheral respondToRequest:aReq withResult:CBATTErrorSuccess];
}
但是,客戶端無法接收任何數據。 有什麼想法? 感謝您的幫助。
你發現任何回答您的問題?我也有同樣的問題 :( – eter