如何从Expo中的WebBrowser重定向到应用程序

时间:2019-10-22 06:45:29

标签: android react-native expo deep-linking

我目前正在使用Expo客户端进行本机响应的Android项目。我正在尝试使用WebBrowser打开网页,并将我的应用程序开发URI传递到网站。网站基本上只是在5秒钟后重定向到给定的URI。但是它似乎从来没有打开任何东西。我使用的代码几乎与此处相同:https://github.com/expo/examples/tree/master/with-webbrowser-redirect。当我将此项目加载到expo并运行时,它重定向很好。但是,当我将网站和应用程序的代码复制到自己的项目中时,网站会打开并显示,但重定向不会执行任何操作。它只是呆在那里。这是打开浏览器的代码。

_openBrowserAsync = async () => {
  try {
    this._addLinkingListener();
    let result = await WebBrowser.openBrowserAsync(
    'https://wexley-auth.firebaseapp.com/?linkingUri=exp://192.168.1.2:19000'
    );
    this._removeLinkingListener();
    this.setState({ result });
  } catch (error) {
    alert(error);
    console.log(error);
  }
};

链接侦听器从不触发应关闭浏览器的回调。我的应用程序URI应该是exp://192.168.1.2:19000,因为通过LAN连接时,expo开发人员工具会向我显示此信息。我也尝试过使用Linking.makeUrl()而不是手动发送字符串形式的URI。这两种方法都不适合我。相关网站代码:

    document.addEventListener("DOMContentLoaded", function(event) {
    var links = document.querySelectorAll('a');
    var baseUri='';

    // Take the uri from the params
    var qs = decodeURIComponent(document.location.search);
    if (qs) {
      baseUri = qs.split('?linkingUri=')[1];
    }

    var redirectInterval = setInterval(function() {
      var countdown = document.querySelector('.countdown');
      var t = parseInt(countdown.innerText, 10);
      t -= 1;
      if (t === 0) {
        clearInterval(redirectInterval);
        window.location.href = baseUri;
      }
    }, 1000);
  });

我错过了一步吗?我是否需要设置打开应用程序的方案,还是应该立即使用?我使用了错误的URI吗?我注意到在示例代码中,app.json具有以下字段,而我的app.json没有:

"scheme": "expo.examples.with-webbrowser-redirect",
"platforms": [
  "android",
  "ios"
]

0 个答案:

没有答案