【问题标题】:My app is being opened by a URL scheme in iOS, how do I get the complete url?我的应用程序正在由 iOS 中的 URL 方案打开,我如何获取完整的 url?
【发布时间】:2020-03-04 16:42:08
【问题描述】:

在我的 iOS 应用程序中,我正在使用另一个应用程序打开 InAppBrowser 并提出问题。然后第二个应用程序再次使用我配置的方案(如 myapp://)调用我的应用程序,完整的 url 类似于 myapp://something/:answer。我设法在 InAppBrowser 中打开了应用程序,然后当它调用 myapp:// 时我的应用程序重新打开,但我需要完整的 url,这样我才能得到答案。

到目前为止,我通过一些示例尝试了我找到的所有内容,例如 https://ionicframework.com/docs/native/deeplinkshttps://github.com/EddyVerbruggen/Custom-URL-scheme,但没有运气。

使用深度链接,我尝试关注文档,但从未调用过订阅,而且我看不到控制台日志。

openSecondApp() {
  this.platform.ready().then( () => {
    if (this.platform.is('ios')) {
      const url = 'secondapp://link/question';

      const options: InAppBrowserOptions = {
        location : 'no',
        hidden : 'no',
        clearcache : 'yes',
        clearsessioncache : 'yes',
        closebuttoncaption : 'Close',
        disallowoverscroll : 'no',
        presentationstyle : 'pagesheet',
      };

      const browser = this.inAppBrowser.create(url, '_system');

      this.deeplinks.route({
        '/': 'ThisPage'
      }).subscribe(match => {
        console.log(match);
      }, nomatch => {
        console.log(nomatch);
      });
    }
  });
}

使用自定义 url 方案,我不明白将 handleOpenURL 函数放在哪里。我试图把它放在 index.html 中 <head> 标记的末尾:

function handleOpenURL(url) {
  console.log("url: " + url);
}

但它永远不会被调用。

(我在 iOS 上,我正在使用带电容器的 Ionic4。)

有人可以分享一个如何做到这一点的例子吗?

【问题讨论】:

    标签: ios angular ionic4 deeplink


    【解决方案1】:

    你必须使用电容器 API

    import { Plugins } from '@capacitor/core';
    
    const { App } = Plugins;
    
    App.addListener('appUrlOpen', (data: any) => {
      // data.url contains the url that is opening your app
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-08
      • 1970-01-01
      • 1970-01-01
      • 2013-11-06
      • 1970-01-01
      • 2017-08-08
      • 2023-04-07
      • 1970-01-01
      相关资源
      最近更新 更多