Xcode - multiple URL Schemes

纵然是瞬间 提交于 2019-12-21 12:11:34

问题


In my app I want to have two Different URL Schemes.
Like One and Two
So the user can open my app with:
one://something
and
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?


回答1:


handleOpenURL is deprecated, so if you're targeting iOS 4.2 or later, you should instead use application:openURL:sourceApplication:annotation:

In both cases, you will be passed an NSURL, on which you can just access the scheme property to find out what scheme was used to access your app.

EDIT: For readability; in your implementation of application:openURL:sourceApplication:annotation:, the code would be something similar to;

if([[url scheme] caseInsensitiveCompare:@"one"] == NSOrderedSame) 
{ 
    /* one here */ 
} else { 
    /* not one here */ 
}


来源:https://stackoverflow.com/questions/14538472/xcode-multiple-url-schemes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!