通过JavaScript打开应用程序(iOS / Android),并将回退重定向到App / Play商店(2016版) [英] Open an app (iOS/Android) via JavaScript, with a fallback redirect to App/Play store (2016 edition)

查看:662
本文介绍了通过JavaScript打开应用程序(iOS / Android),并将回退重定向到App / Play商店(2016版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于:网站,iOS和Android应用程序,已注册urlschememyapp://。



目标:在网站上有一个显示iOS / Android设备的链接安装了应用程序。点击该链接应该打开应用程序并调用特定的逻辑(由应用程序处理,基本上类似于来自苹果的通用链接,但没有阴影网站链接)。



到期安全约束检测是否安装了应用程序是麻烦没有webview cookie魔术。鉴于此,尝试通过JavaScript打开应用程序的最佳方法是什么,如果失败则调用回退重定向?



此线程的解决方案:(完全披露:我在分支机构团队中),我们看到了iOS 9.2测试版,并希望我们的Apple雷达(错误报告)和有影响力的合作伙伴可以激励Apple在发布之前解决它。不幸的是,对于iOS开发人员来说,情况并非如此。 Apple对我们关注的回应非常清楚他们希望每个人都做的事情:采用Universal Links。








2016年的解决方案



让单个链接无处不在的唯一方法(包括在安装或应用后备路由到应用程序) URL(如果不是)必须包含在iOS上使用Universal Links。当然,iOS中实际上并不支持Universal Links,因此仍然需要自定义URI方案的特定边缘情况(Chrome和Gmail是两个很好的例子)。您需要检测这些并构建自定义处理。



大多数公司都没有资源投入一名全职工程师(或两名),这就是为什么Pinterest,Tinder,Airbnb,Jet.com, Yummly等都采用了 Branch.io 或Firebase动态链接等链接平台。


Given: Website, iOS and Android applications, registered urlscheme "myapp://".

Goal: on the website have a link shown to iOS/Android devices with app installed. Clicking on that link should open the app and invoke specific logic (handled by the app, essentially like "universal links" from apple, but without shadowing website links).

Due to security constraints detecting if an app is installed is troublesome without webview cookie magic. Given that, what would be the best approach to try and open an app via JavaScript, and invoke a fallback redirect if that fails?

Solution from this thread: Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps? doesn't work with iOS10. Not sure about Android.

解决方案

In 2016, this is impossible to achieve via Javascript alone

You can still use the approach on Android, but Apple made changes in iOS 9.2 that mean this is essentially useless on iOS devices.


How it used to work on iOS

The way this was done in the past was to attempt to open up the app in Javascript by setting window.location to the custom URI path that you wanted.

window.location = "imdb://title/tt3569230";

App not installed

The problem with this is that when the app is not installed, it shows a ‘Cannot Open Page’ error. I’m sure you’ve all seen it. It’s the bane of deep linking. There was a glorious period during iOS 7 and iOS 8 where it was possible to bypass this, but the golden age has passed.

In order to avoid this, you had to add some Javascript to your page where you would redirect away to the App Store. This way, the user was not left with an error on the screen.

window.location = 'imdb://title/tt3569230';
setTimeout(function() {
  window.location = 'itms-apps://itunes.apple.com/us/app/imdb-movies-tv/id342792525'
}, 250);

App installed

When the app was installed, it would display the modal below, prompting the user if they want to open the app:

What happens now is that in iOS 9, Apple changed the Open in "[app]" modal from a Javascript blocking modal to a non-blocking modal. This means when you try to open up the app via a Javascript redirect to a custom URI scheme, the modal will no longer block Javascript from executing, with the result that the fallback redirect to the App Store will execute immediately before the user can tap the 'Open' button.

At Branch.io (full disclosure: I'm on the Branch team), we saw this coming in the iOS 9.2 betas and were hopeful that our Apple radars (bug reports) and influential partners could motivate Apple to resolve it before release. Unfortunately for iOS developers, it was not to be. Apple’s response to our concerns made perfectly clear what they wanted everyone to do: adopt Universal Links.


Solution for 2016

The only way to have a single link that works everywhere (including routing into apps if they are installed or to fallback web URLs if they are not) must include using Universal Links on iOS. Of course, Universal Links aren't actually supported everywhere in iOS yet, so there are specific edge cases where custom URI schemes are still required (Chrome and Gmail being two big examples). You'll need to detect these and build custom handling.

Most companies don't have the resources to devote a full-time engineer (or two) to this, which is why Pinterest, Tinder, Airbnb, Jet.com, Yummly, etc., have all adopted linking platforms like Branch.io or Firebase Dynamic Links.

这篇关于通过JavaScript打开应用程序(iOS / Android),并将回退重定向到App / Play商店(2016版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆