iOS9:如果可能,尝试通过方案打开应用程序,否则重定向到应用程序商店 [英] iOS9: Try to open app via scheme if possible, or redirect to app store otherwise

查看:31
本文介绍了iOS9:如果可能,尝试通过方案打开应用程序,否则重定向到应用程序商店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于 iOS9 的!

我有一个 HTML 登录页面,如果应用已安装,我尝试通过 URL 架构将用户重定向到我的应用,或者重定向到 应用商店否则.

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.

我的代码是:

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);
}

问题是 iframe 技巧在 Safari iOS9 中不起作用.

The problem is that the iframe trick doesn't work in Safari iOS9.

知道为什么吗?

我的 iframe 技巧基于 这个答案.

My iframe trick based on this answer.

推荐答案

iframe 技巧不再有效——我猜测 Apple 知道它将鼓励更多开发人员更快地实施通用链接.

The iframe trick no longer works -- my guess is that Apple knows it will encourage more developers to implement Universal Links, more quickly.

您仍然可以设置 window.location='your-uri-scheme://'; 并在 500 毫秒后回退到 App Store.如果您采用这种方法,弹出窗口之间会出现跳舞",就像我们在 Branch 所做的那样(如果 Universal链接无效).

You can still set window.location='your-uri-scheme://'; and fallback to the App Store after 500ms. 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).

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);

我希望我有一个更好的答案给你.iOS 9 肯定更受限制.

I wish I had a better answer for you. iOS 9 is definitely more limited.

有关通用链接所需内容的有用概述,请查看我的回答 此处阅读本教程

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

这篇关于iOS9:如果可能,尝试通过方案打开应用程序,否则重定向到应用程序商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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