可以在iOS中处理您自己的http URL方案吗? [英] Possible to handle your own http URL schemes in iOS?

查看:84
本文介绍了可以在iOS中处理您自己的http URL方案吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS上的iTunes,App Store和YouTube清楚地注册了http:// ... URL方案来打开他们的应用程序。



任何人都可以这样做,而不仅仅是你的自己的协议?



我想这样做的原因是我正在为一个节日开发应用程序。我希望截取网站上特定页面的链接,然后启动应用程序(如果已安装)。



到目前为止,我没有太多运气

解决方案

对于http://URL(以及我认为Apple和Spotify所做的)这样做的方法是:


  1. 注册自定义URL方案其他答案已显示


  2. 设置您的HTTP网址以指向真实网页。


  3. 如果在iOS上,请在该页面上放置一个脚本以重定向到您的自定义网址。


例如,这是一个示例页面,它将带您到特定用户或Twitter网站的Twitter应用程序,具体取决于您是在网络上还是在iOS设备上:

 <!DOCTYPE html> 
< html>
< head>
< meta charset =utf-8>
< title> Twitter< / title>
< / head>
< body>
< script type =text / javascript>
var username = document.location.search.substr(1);
document.location.replace(在window.navigator中
standalone?
'twitter:@'+ username:// iOS
'http://twitter.com/ +用户名); //其他人
< / script>
< / body>
< / html>

在此尝试: http://bl.ocks.org/d/3153819/?mckamey


iTunes, App Store and YouTube on iOS clearly register http://... URL schemes to open their apps.

Can anyone do that, not just your own protocol?

The reason I want to do this is that I am working on an app for a festival. I want to "intercept" links to specific pages on the website and launch the app instead, if installed.

So far I have no had much luck

解决方案

The way you can do this for "http://" URLs (and what I think Apple and Spotify do) this is to:

  1. Register a custom URL scheme like the other answers have shown.

  2. Set up your HTTP URL to point to a real webpage.

  3. Put a script on that page to redirect to your custom URL if is on iOS.

For example, here is a sample page which will take you to the Twitter app for a particular user or the Twitter website depending upon if you are on the web or on your iOS device:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Twitter</title>
</head>
<body>
    <script type="text/javascript">
        var username = document.location.search.substr(1);
        document.location.replace(
            "standalone" in window.navigator ?
            'twitter:@'+username :              // iOS
            'http://twitter.com/'+username);    // others
    </script>
</body>
</html>

Try it out here: http://bl.ocks.org/d/3153819/?mckamey

这篇关于可以在iOS中处理您自己的http URL方案吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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