DSBridge-Android icon indicating copy to clipboard operation
DSBridge-Android copied to clipboard

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

Open donne1226 opened this issue 5 years ago • 6 comments


    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

donne1226 avatar Apr 20 '19 04:04 donne1226

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

xiaoheban avatar Jun 04 '19 02:06 xiaoheban

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

donne1226 avatar Jun 04 '19 03:06 donne1226

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

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

xiaoheban avatar Jun 04 '19 03:06 xiaoheban

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

donne1226 avatar Jun 04 '19 03:06 donne1226

好的 谢谢

xiaoheban avatar Jun 04 '19 05:06 xiaoheban

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

H-Sven avatar Jul 28 '21 02:07 H-Sven