我实现了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];
}
但是,客户端无法接收任何数据。
任何的想法?
谢谢你的帮助。
最佳答案
根据Apple在CoreBluetooth上的文档,您应该使用:
- (void)respondToRequest:(CBATTRequest *)request withResult:(CBATTError)result;
回复中心。当您收到阅读请求时,这也是一种选择