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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:38:08  来源:igfitidea点击:

Xcode - multiple URL Schemes

iphoneiosobjective-cxcodeurl-scheme

提问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
and
two://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

handleOpenURLis 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 schemepropertyto 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 */ 
}