使用同步请求处理核心蓝牙代表的最佳方法是什么? 根据要求,我必须实现以下方法:
-(NSData *)dataWithRequest:(NSData *)request
characteristic:(CBCharacteristic *)characteristic {
[_peripheralActive writeValue:request
forCharacteristic:characteristic
type:CBCharacteristicWriteWithoutResponse];
// how to wait for response with _myData here?
return _myData;
}
// CBPeripheralDelegate采用
-(void)peripheral:(CBPeripheral *)peripheral
didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic
error:(NSError *)error {
// do staff
_myData = characteristic.value;
}
任何在同一胎面/队列中等待的人都将阻止委托,在另一个胎面/队列中等待将返回当前的_myData。请帮忙。