可以在 iOS 中处理您自己的 http URL 方案吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4403992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:16:37  来源:igfitidea点击:

Possible to handle your own http URL schemes in iOS?

iosurl-scheme

提问by baswell

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

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

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

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

回答by mckamey

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

您可以为“http://”网址(以及我认为 Apple 和 Spotify 所做的)执行此操作的方法是:

  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.

  1. 注册一个自定义 URL 方案,如其他答案所示

  2. 设置您的 HTTP URL 以指向一个真实的网页。

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

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:

例如,下面是一个示例页面,它会将您带到特定用户的 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(
            "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

在这里试试:http: //bl.ocks.org/d/3153819/?mccamey

回答by Marcus Adams

iOS 9 supports Universal Links, which allows iOS to launch an app based on a standard http://URL (based on the hostname) without the user having to go through Safari.

iOS 9 支持通用链接,它允许 iOS 启动基于标准http://URL(基于主机名)的应用程序,而无需用户通过 Safari。

It requires some web server configuration (you need a website), but once setup, the registered app will open the link instead of Safari.

它需要一些 Web 服务器配置(您需要一个网站),但是一旦设置,注册的应用程序将打开链接而不是 Safari。

For the users that don't have iOS 9, you can use Smart Bannersto ease the experience.

对于没有 iOS 9 的用户,您可以使用智能横幅来简化体验。

回答by Marius Ciocanel

Unfortunately I don't think you can do that. You can register your own custom scheme e.g yourFestival:// and pass data from the outside world (SMS , email , other apps) to your app.

不幸的是,我认为你不能这样做。您可以注册您自己的自定义方案,例如 yourFestival:// 并将数据从外部世界(短信、电子邮件、其他应用程序)传递到您的应用程序。

I wrote a blog post about this here : Using custom schemes and passing data between iOS apps.

我在这里写了一篇关于此的博客文章:使用自定义方案并在 iOS 应用程序之间传递数据。

I hope this helps.

我希望这有帮助。

回答by Eiko

No, you can only register custom schemes.

不,您只能注册自定义方案。

And I cannot see Apple doing this, either...

而且我也看不到苹果这样做......