[英]iOS9: Try to open app via scheme if possible, or redirect to app store otherwise
My question is about iOS9 only! 我的问题只是关于iOS9!
I have an HTML
landing page, and I try to redirect the user to my app via URL scheme if the app is installed, or redirect to the Appstore otherwise. 我有一个HTML
登录页面,如果安装了应用程序,我尝试通过URL方案将用户重定向到我的应用程序,否则重定向到Appstore 。
My code is: 我的代码是:
document.addEventListener("DOMContentLoaded", function(event) {
var body = document.getElementsByTagName('body')[0];
body.onclick = function () {
openApp();
};
});
var timeout;
function preventPopup() {
clearTimeout(timeout);
timeout = null;
window.removeEventListener('pagehide', preventPopup);
}
function openApp(appInstanceId, platform) {
window.addEventListener('pagehide', preventPopup);
document.addEventListener('pagehide', preventPopup);
// create iframe
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
iframe.setAttribute("style", "display:none;");
iframe.src = 'myscheme://launch?var=val';
var timeoutTime = 1000;
timeout = setTimeout(function () {
document.location = 'https://itunes.apple.com/app/my-app';
}, timeoutTime);
}
The problem is that the iframe
trick doesn't work in Safari
iOS9
. 问题是iframe
技巧在Safari
iOS9
。
Any idea why? 知道为什么吗?
The iframe trick no longer works -- my guess is that Apple knows it will encourage more developers to implement Universal Links, more quickly. iframe技巧不再适用 - 我的猜测是Apple知道它会鼓励更多开发人员更快地实施Universal Links。
You can still set window.location='your-uri-scheme://';
你仍然可以设置window.location='your-uri-scheme://';
and fallback to the App Store after 500ms. 并在500ms后回退到App Store。 There is a "dance" between popups if you take this approach, as we do at Branch (we do as a fallback if Universal Links don't work). 如果采用这种方法,弹出窗口之间会有“跳舞”,就像我们在分支机构那样 (如果Universal Links不起作用,我们会作为后备)。
window.location = 'your-uri-scheme://'; // will result in error message if app not installed
setTimeout(function() {
// Link to the App Store should go here -- only fires if deep link fails
window.location = "https://itunes.apple.com/us/app/myapp/id123456789?ls=1&mt=8";
}, 500);
I wish I had a better answer for you. 我希望我能给你一个更好的答案。 iOS 9 is definitely more limited. iOS 9肯定更受限制。
For a helpful overview of what's needed for Universal Links should you go that route, check out my answer here or read this tutorial 对于你应该走这条路什么需要通用链接有用的概述,检查出我的答案在这里或阅读本教程
As already mentioned setting window.location
on iOS 9 still works. 如前所述,在iOS 9上设置window.location
仍然有效。 However, this brings up an Open in App dialog. 但是,这会打开一个Open in App对话框。 I've put an example on https://bartt.me/openapp that: 我在https://bartt.me/openapp上举了一个例子:
Look at the source of https://lab.bartt.me/openapp for more information. 有关更多信息, 请查看https://lab.bartt.me/openapp的来源。
Maybe try giving you app support to Universal Links 也许尝试为Universal Links提供应用程序支持
Idea: Avoid custom (JavaScript, iframe) solutions in Safari, replace you code with a supported Universal Link. 想法:避免在Safari中使用自定义(JavaScript,iframe)解决方案,用支持的通用链接替换您的代码。
Example 例
<html>
<head>
...
</head>
<body>
<div class"app-banner-style">
<a href="http://yourdomain.com">In app open</a>
</div>
...content
</body>
</html>
if you app support Universal Links (eg yourdomain.com), you muss configure your domain (and path) and iOS9 should be react to it link opening you App. 如果您的应用程序支持Universal Links(例如yourdomain.com),那么您可以配置您的域(和路径),iOS9应该对它进行反应,打开您的App。 That is only theory , but I guess should be work :) 这只是理论 ,但我想应该工作:)
https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html#//apple_ref/doc/uid/TP40016308-CH12 https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html#//apple_ref/doc/uid/TP40016308-CH12
iframe hack doesn't work in ios9 anymore. iframe hack不再适用于ios9。 Possible solution is use two buttons. 可能的解决方案是使用两个按钮 Example: 例:
$('#goToStoreBtn').text( "go to store" ).click(function(event){
event.preventDefault();
event.stopPropagation();
window.location = storeUrl; // https://itunes.apple.com/...
});
$('#goToAppBtn').text( "go to app" ).click(function(event){
event.preventDefault();
event.stopPropagation();
window.location = appUrl; // myApp://...
});
This is relatively old thread, but I have created a library that supports deeplinking on most of the modern mobile browsers. 这是相对较旧的线程,但我创建了一个支持大多数现代移动浏览器的深层链接的库。 But this requires separate deeplinking page which needs to be hosted in different domain to support universal linking in ios9 facebook browser. 但这需要单独的深层链接页面,需要托管在不同的域中以支持ios9 facebook浏览器中的通用链接。
https://github.com/prabeengiri/DeepLinkingToNativeApp https://github.com/prabeengiri/DeepLinkingToNativeApp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.