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

IOS 上的 iTunes、 App Store 和 YouTube 显然注册了 http://... URL 方案来开放他们的应用程序。

除了你自己的协议,还有人能做到吗?

我想这样做的原因是,我正在为一个节日的应用程序工作。我想“拦截”网站上的特定网页的链接,并启动应用程序,而不是,如果安装。

到目前为止,我还没有什么好运气

48340 次浏览

No, you can only register custom schemes.

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

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.

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

I hope this helps.

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 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.

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

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

The question is old, but since I came across to this page now, years later, when searching for answer to the same question, I'll add answer on how to do it now:

Use Universal links. First enable "Associated Domains" on your App ID in developer.apple.com. Then add your domain as applink in Xcode (select Target->Signing & Capabilities->Associated Domains) and then create an apple-app-site-association file on your website.

Details are explained here.