Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - multiple URL Schemes

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?

like image 540
Jonathan Gurebo Avatar asked Jan 26 '13 15:01

Jonathan Gurebo


People also ask

How do I add a URL type in Xcode?

Register your URL schemeRegister your scheme in Xcode from the Info tab of your project settings. Update the URL Types section to declare all of the URL schemes your app supports, as shown in the following illustration. In the URL Schemes box, specify the prefix you use for your URLs.

Where is URL scheme in Xcode?

Setting up URL Scheme In Xcode, under your project configuration, select your target and navigates to Info tab. You'll see an URL Types section at the bottom.

What is deep linking in iOS?

Deep linking consists of using a hyperlink that links to a specific piece of content within an app. The specific content could be a specific view, a particular section of a page, or a certain tab. To see an example, download the Twitter app. Log into it and close it.


1 Answers

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 */ 
}
like image 170
Joachim Isaksson Avatar answered Sep 23 '22 19:09

Joachim Isaksson