我正在创建一个使用CoreBluetooth.framework的本机模块。我正在尝试实施一个RCT_EXPORT_METHOD
来调用this bluetooth write method。
RCT_EXPORT_METHOD(write:(CBUUID *)peripheralUuid
forCharacteristicUuid:(CBUUID *)characteristicUuid
data:(NSData *)data /* <== HOW DO I PASS THIS IN? */
withResponse:(BOOL)withResponse)
{
CBPeripheral *peripheral = /* my peripheral */;
CBCharacteristic *characteristic = /* my characteristic */;
if (peripheral && characteristic) {
[peripheral
writeValue:data
forCharacteristic:characteristic
type:withResponse ? 0 : 1];
}
}
我需要使用RCTConvert
通过本机网桥获取NSData
参数?
答案 0 :(得分:2)
在对source code进行进一步研究后,我发现你无法声明NSData
参数,你必须将其作为base64编码的字符串(NSString
)传递,然后使用RCTConvert
将其转换为NSData
。
RCT_EXPORT_METHOD(write:(CBUUID *)peripheralUuid
forCharacteristicUuid:(CBUUID *)characteristicUuid
data:(NSString *)data
withResponse:(BOOL)withResponse)
{
// ....
[peripheral
writeValue:[RCTConvert NSData:data]
forCharacteristic:/* ... */
type:/* ... */];
}