将字节数组转换为Ti.Buffer

时间:2018-07-26 10:24:53

标签: appcelerator appcelerator-titanium appcelerator-alloy appcelerator-hyperloop

我在钛项目中字节数组遇到一些麻烦,希望有人能帮助我...

我必须使用Appcelerator Titanium连接到多个蓝牙设备。

您可以在BLE演示应用程序上看到,我们必须使用已定义和硬编码的字节数组(与目标C中的Java相同)对BLE设备进行身份验证

Android:

   byte pwd[] = {(byte) 0xA1, (byte) 0xA4, (byte) 0x24, (byte) 0xA4};
   characteristic.setValue(pwd);

iOS:

   Byte writePWD[5] = {0xA1, 0xA2, 0xA3, 0xA4};
   NSData *nsWritePwd = [[NSData alloc] initWithBytes:writePWD length:4];

在我的TI项目中,我必须在Ti.Buffer中创建一个字节数组,该字节数组将存储在特性中。 但是如何在TI / Javascript中构建ByteArray?

以下示例无法正常工作。 :-(

   var writePwd = Ti.createBuffer({ value: [0xA1, 0xA2, 0xA3, 0xA4], type: Ti.Codec.TYPE_BYTE, length: 4});

有人知道吗? :)

(也许使用Hyperloop?)

0 个答案:

没有答案