wendux / DSBridge-Android

:earth_americas: A modern cross-platform JavaScript bridge, through which you can invoke each other's functions synchronously or asynchronously between JavaScript and native.
3.73k stars 613 forks source link

js 使用promise 调用 native 能拿到结果 但报错 #128

Open donne1226 opened 5 years ago

donne1226 commented 5 years ago

    getLocation() {
      let p = new Promise(resolve => {
        dsBridge.call("getLocation", function (location) {
          resolve(location)
        });
      });
      return p
    },

    getFingerprint() {
      let p = new Promise(resolve => {
        dsBridge.call("getFingerprint", function (fingerprint) {
          resolve(fingerprint)
        });
      });
      return p
    },

    getinfo() {
      Promise.all([this.getLocation(), this.getFingerprint()]).then((result) => {
        console.log(result);
      }).catch((error) => {

      })
    }

执行getInfo 能成功拿到两个promise 返回的结果,但是报错 dscb is not defined

xiaoheban commented 5 years ago

我遇到了同样的问题 请问你解决了么

donne1226 commented 5 years ago

@xiaoheban 没有解决。我选择忽略报错,其实没影响

xiaoheban commented 5 years ago

@xiaoheban 没有解决。我选择忽略报错,其实没影响

我这边遇到一个问题,原生部分也是耗时的操作,如果在js连续调用改操作,第二次调用的时候如果第一次操作还没有返回,第一次回调js的数据就会被覆盖

donne1226 commented 5 years ago

@xiaoheban 那你可以禁止重复调用。比如加个loading,等返回结果再解开

xiaoheban commented 5 years ago

好的 谢谢

H-Sven commented 2 years ago

请问你解决了吗? 我也遇到了这个问题