等待peripheral:didUpdateValueForCharacteristic:error:with sync request

时间:2015-04-01 01:33:32

标签: ios bluetooth

使用同步请求处理核心蓝牙代表的最佳方法是什么? 根据要求,我必须实现以下方法:

-(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。请帮忙。

0 个答案:

没有答案