小编Ken*_*Ken的帖子

如何正确实现didReceiveWriteRequests?iOS6 CoreBluetooth

我实现了iOS CoreBluetooth客户端和服务器来发送数据

client site
[self.connectedPeripheral writeValue:mainData forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
Run Code Online (Sandbox Code Playgroud)

- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic 
{
   NSString *s= [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding];
   NSLog(@"didWriteValue characteristic.value: %@ ", s);
} 
Run Code Online (Sandbox Code Playgroud)

和服务器站点

- (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];
}
Run Code Online (Sandbox Code Playgroud)

但是,客户端无法接收任何数据.任何的想法?谢谢你的帮助.

bluetooth ios core-bluetooth ios6

19
推荐指数
1
解决办法
2907
查看次数

标签 统计

bluetooth ×1

core-bluetooth ×1

ios ×1

ios6 ×1