我实现了 iOS 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];
}
但是,客户端无法接收任何数据。任何想法?谢谢你的帮助。