Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps?(是否可以为 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:
- 检查用户代理是否是 iPhone/iPod Touch 的用户代理
- 检查
appInstalled
cookie - 如果 cookie 存在并设置为 true,请将
window.location
设置为your-uri://
(或做重定向服务器端) - 如果 cookie 不存在,请打开您知道您的站点名称有 iPhone 应用程序吗?"带有是的,我已经得到它"、不,但我很想尝试一下"和别管我"按钮的模态.
- Check if the user-agent is that of an iPhone/iPod Touch
- Check for an
appInstalled
cookie - If the cookie exists and is set to true, set
window.location
toyour-uri://
(or do the redirect server side) - 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.
- 是"按钮将 cookie 设置为 true 并重定向到
your-uri://
- 否"按钮重定向到http://itunes.com/apps/yourappname"这将在设备上打开 App Store
- 别管我"按钮将 cookie 设置为 false 并关闭模式
- The "Yep" button sets the cookie to true and redirects to
your-uri://
- The "Nope" button redirects to "http://itunes.com/apps/yourappname" which will open the App Store on the device
- 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 方案?
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01