简体   繁体   English

iOS9:尽可能尝试通过方案打开应用程序,否则重定向到应用程序商店

[英]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? 知道为什么吗?

My iframe trick based on this answer. 我的iframe技巧基于这个答案。

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上举了一个例子:

  1. Launches Twitter when the Open in Twitter app is clicked. 点击Twitter上的Open应用程序时启动Twitter。
  2. Falls back to the Twitter app in the App Store. 回到App Store中的Twitter应用程序。
  3. Redirects to Twitter or the App Store without the user selecting Open in the Open in App dialog. 无需用户在“ 在应用程序打开”对话框中选择“ 打开”即可重定向到Twitter或App Store。
  4. Works in all browsers on iOS and Android. 适用于iOS和Android上的所有浏览器。

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.

相关问题 iOS App URL Scheme启动应用程序或打开应用程序商店 - iOS App URL Scheme launch application or open app store 通过 JavaScript 打开应用程序(iOS/Android),后备重定向到 App/Play 商店(2016 版) - Open an app (iOS/Android) via JavaScript, with a fallback redirect to App/Play store (2016 edition) 使用 javascript 将应用程序重定向到 ios 商店 - Redirect app to the ios store using javascript 检测IOS中是否存在应用,否则重定向到应用商店Javascript - Detect if an app is present in IOS else redirect to app store Javascript Android - 方案 URL - 链接重定向到应用程序 - Android - Scheme URL - link redirect to app 使用jQuery和Javascript打开IOS相机应用并将其存储为变量 - Using jQuery and Javascript to open the IOS camera app and store it as a variable 如果已安装,则将用户从 iOS 浏览器重定向到 App,如果未安装,则将用户重定向到 App Store - 如 Yelp - Redirect user from iOS browser to App if installed, or to App Store if not - like Yelp 在移动浏览器中打开时,是否可以从 React 应用程序重定向到已安装的 Flutter 应用程序页面 - Is it Possible to redirect to installed flutter app page from react app when open in mobile browser 通过iOS和Android中的URL方案打开Snapchat和Instagram - Open Snapchat and Instagram via URL Scheme in iOS and Android 如何使用自定义协议打开应用程序,否则如果未安装则下载? - How to open app using custom protocol otherwise download if not installed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM