首页 > 解决方案 > 问:当我使用 cordova-plugin-ble-central.I 写在 ios 上但它返回 'null'

问题描述

我正在使用cordova-plugin-ble-contral,我在ios上写,但它返回'null',在android上返回'ok'。我在ios上写得不好。

我在android和ios上写得很好,我做hybird APP。

  connectTo() {
  var that = this;

  var Hex = "";
  Hex += addZero(stringToSixteen(this.ssid), 32);
  Hex += "07";
  Hex += addZero(stringToSixteen(this.password), 64);
  Hex += "A5A5";

  var data = HexString2Bytes(Hex);
  let length = Math.ceil(data.byteLength / 20); 
  var success = function(reason) {
    // it will return null? 
    that.$router.push({
      name: "isConnect",
      query: {
        deviceId: that.deviceId,
        ssid: that.ssid,
        password: that.password
      }
    });
  };
  var failure = function(reason) {
     alert(reason);
    that.$router.push({
      name: "isConnect",
      query: {
        deviceId: that.deviceId,
        ssid: that.ssid,
        password: that.password
      }
    });
  };

  //分包发送msg
  for (let i = 0; i < length; i++) {
    var buffers = data.slice(i * 20, (i + 1) * 20);
    ble.writeWithoutResponse(
      this.deviceId,
      this.serviceUUID,
      this.characteristicToWrite,
      buffers,
      success,
      failure
    );
  }
},

它表明我写得很好,但实际上并没有发送消息。

标签: ioscordovabluetoothbluetooth-lowenergycordova-plugins

解决方案


推荐阅读