Xcode - 多个 URL Schemes
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14538472/
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
Xcode - multiple URL Schemes
提问by Jonathan Gurebo
In my app I want to have two Different URL Schemes.
Like Oneand Two
So the user can open my app with:one://something
andtwo://something
在我的应用程序中,我想要两个不同的 URL 方案。
像一和二
所以用户可以打开我的应用程序:one://something
和two://something
I am using this:
我正在使用这个:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
}
How will the app know if the user types one or two?
应用程序如何知道用户是否输入了一两个?
回答by Joachim Isaksson
handleOpenURL
is deprecated, so if you're targeting iOS 4.2 or later, you should instead use application:openURL:sourceApplication:annotation:
handleOpenURL
已弃用,因此如果您的目标是 iOS 4.2 或更高版本,则应改为使用 application:openURL:sourceApplication:annotation:
In both cases, you will be passed an NSURL
, on which you can just access the scheme
propertyto find out what scheme was used to access your app.
在这两种情况下,您都将获得一个NSURL
,您可以通过该scheme
属性访问该属性以找出用于访问您的应用程序的方案。
EDIT: For readability; in your implementation of application:openURL:sourceApplication:annotation:
, the code would be something similar to;
编辑:为了可读性;在您的实现中application:openURL:sourceApplication:annotation:
,代码将类似于;
if([[url scheme] caseInsensitiveCompare:@"one"] == NSOrderedSame)
{
/* one here */
} else {
/* not one here */
}