EddyVerbruggen / cordova-plugin-safariviewcontroller

:tiger: :elephant: :crocodile: Forget InAppBrowser for iOS - this is way better for displaying read-only web content in your PhoneGap app
MIT License
281 stars 143 forks source link

A solution for following deep links #182

Open terreng opened 3 years ago

terreng commented 3 years ago

Great plugin, but one issue with using an in app browser is that it doesn't follow universal/deep links to other apps. It's not a great experience using a website like youtube.com in the in app browser instead of just opening the link in the YouTube app.

This isn't a problem with this plugin, but rather a limitation of SafariViewController / custom Chrome tabs.

So today I created cordova-plugin-open-app-link. This plugin checks if there's an app installed to handle the link, and opens it if so. Otherwise it returns false (and doesn't do anything), which allows you to use SafariViewController as a fallback.

Here's an example of how to use it with your plugin:

OpenAppLink.open(url, function(opened) {
  if (!opened) {
    SafariViewController.isAvailable(function (available) {
      if (available) {
        SafariViewController.show({
          url: url
        })
      } else {
        window.open(url, '_blank', 'location=yes');
      }
    })
  }
})

The result is the ultimate link experience: Open in native app if it's installed, otherwise use in app browser, otherwise use system browser.

I'm going to be using this in my production app, and I think others might desire this behavior too. Can you update the README to mention how deep links aren't followed, and this is the solution? Thanks!