是否可以为 iPhone 应用程序(如 YouTube 和地图)注册基于 http+域的 URL 方案?

Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps?(是否可以为 iPhone 应用程序(如 YouTube 和地图)注册基于 http+域的 URL 方案?)

本文介绍了是否可以为 iPhone 应用程序(如 YouTube 和地图)注册基于 http+域的 URL 方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让 iOS 打开我域中的 URL(例如 http://martijnthe.nl)每当应用程序安装在手机上时我的应用程序,如果未安装,则使用 Mobile Safari.

I'd like to have iOS to open URLs from my domain (e.g. http://martijnthe.nl) with my app whenever the app is installed on the phone, and with Mobile Safari in case it is not.

我读到可以为此创建一个唯一的协议后缀并将其注册到 Info.plist 中,但如果未安装该应用程序,Mobile Safari 会出错.

I read it is possible to create a unique protocol suffix for this and register it in the Info.plist, but Mobile Safari will give an error in case the app is not installed.

什么是解决方法?

一个想法:

1) 使用在任何桌面浏览器中打开的 http://URL 并通过浏览器呈现服务

1) Use http:// URLs that open in any desktop browser and render the service through the browser

2) 检查 User-Agent,如果它是 Mobile Safari,打开 myprotocol://URL 以(尝试)打开 iPhone 应用程序并让它打开 Mobile iTunes 以下载应用程序,以防尝试失败

2) Check the User-Agent and in case it's Mobile Safari, open a myprotocol:// URL to (attempt) to open the iPhone app and have it open Mobile iTunes to the download of the app in case the attempt fails

不确定这是否可行...建议?谢谢!

Not sure if this will work... suggestions? Thanks!

推荐答案

我认为最不打扰的方式如下:

I think the least intrusive way of doing this is as follows:

  1. 检查用户代理是否是 iPhone/iPod Touch 的用户代理
  2. 检查 appInstalled cookie
  3. 如果 cookie 存在并设置为 true,请将 window.location 设置为 your-uri://(或做重定向服务器端)
  4. 如果 cookie 不存在,请打开您知道您的站点名称有 iPhone 应用程序吗?"带有是的,我已经得到它"、不,但我很想尝试一下"和别管我"按钮的模态.
  1. Check if the user-agent is that of an iPhone/iPod Touch
  2. Check for an appInstalled cookie
  3. If the cookie exists and is set to true, set window.location to your-uri:// (or do the redirect server side)
  4. If the cookie doesn't exist, open a "Did you know Your Site Name has an iPhone application?" modal with a "Yep, I've already got it", "Nope, but I'd love to try it", and "Leave me alone" button.
  1. 是"按钮将 cookie 设置为 true 并重定向到 your-uri://
  2. 否"按钮重定向到http://itunes.com/apps/yourappname"这将在设备上打开 App Store
  3. 别管我"按钮将 cookie 设置为 false 并关闭模式
  1. The "Yep" button sets the cookie to true and redirects to your-uri://
  2. The "Nope" button redirects to "http://itunes.com/apps/yourappname" which will open the App Store on the device
  3. The "Leave me alone" button sets the cookie to false and closes the modal

我玩过但发现有点笨拙的另一个选项是在 Javascript 中执行以下操作:

The other option I've played with but found a little clunky was to do the following in Javascript:

setTimeout(function() {
  window.location = "http://itunes.com/apps/yourappname";
}, 25);

// If "custom-uri://" is registered the app will launch immediately and your
// timer won't fire. If it's not set, you'll get an ugly "Cannot Open Page"
// dialogue prior to the App Store application launching
window.location = "custom-uri://";

这篇关于是否可以为 iPhone 应用程序(如 YouTube 和地图)注册基于 http+域的 URL 方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:是否可以为 iPhone 应用程序(如 YouTube 和地图)注册基于 http+域的 URL 方案?

基础教程推荐