How to register a custom app opening URL scheme with Xcode 4?

IphoneIosIpadXcode4

Iphone Problem Overview


Xcode4 is asking for a huge number of arguments just to make this simple thing possible:

NSString *stringURL = @"twitterriffic://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Xcode 4 Info.plist editor

What are all these properties for? Why an image? Must I repeat the app identifier here? What role to choose if I want anyone to be able to call this URL to open my app? And what are these Additional url type properties for?

I found no Xcode4-related tutorial how to register such an URL scheme with Xcode 4.

Iphone Solutions


Solution 1 - Iphone

Edit your AppName-Info.plist file

  • Open "Supporting Files" (folder) on left and click the "YourAppName-Info.plist"
  • Choose a row like "Bundle creator OS Type Code" and mouse over row and click the (+) symbol
  • This creates a new row and type "URL types"
  • Click the arror to left and see Item 0 and you'll rename the value in Item 0 to "URL Schemes" as shown
  • Then edit the field in Item 0 and type in your prototocol; I typed in "goomzee" as shown

Now if I install this app on my simulator, and open Safari and type "goomzee://" in the address bar it will launch my app.

Solution 2 - Iphone

Yup, this stuff isn't straightforward is it ?

I've outlined the steps required to register a custom URL here: Custom URLs

But, basically the key to it is setting up a "URL Types" value in your .plist file. Here's what it looks like in XCode 5:

URL types

In this example, I've registered the MKB prefix, so now, I can use this new type of URLs in hyperlinks on webpages, and emails (if I read an email in the iPad Mail app):

Mail app

If a user taps on one of these links, my iPad app will start up, and I can access the full URL string, to extract the other parameters from the URL (eg "DocumentNumber=100")

The only gotcha is that I have yet to work out how to test whether a user has an iPad app installed which can recognise a particular prefix.

If they haven't, and they tap on one of these MKB:// links on their iPad, they'll get an ugly error message:

Nope

Solution 3 - Iphone

You can continue to register your custom URL by editing your app's info.plist file (as shown in one of your previous questions). The new editor in Xcode 4 is supposed to be a convenience to make it easier to add the entries - all it is doing is making the same info.plist changes that you would do manually. If you want to use the new editor then you only need to fill in the 'Identifier' and the 'URL Schemes' boxes. You don't need an image, icon or additional URL properties.

The other properties (icon etc) are not well documented but seem to be applicable only on Mac OS X and might be used in the Finder's Get Info dialog to display what types of URL a particular app can open. For example, take a look at the Launch Services Programming Guide.

Solution 4 - Iphone

What you change in that editor is also reflected in your project's info plist file. It takes the form of ProjectName-Info.plist. Hopefully that helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionopenfrogView Question on Stackoverflow
Solution 1 - IphoneMike S.View Answer on Stackoverflow
Solution 2 - IphoneMike GledhillView Answer on Stackoverflow
Solution 3 - IphoneRobin SummerhillView Answer on Stackoverflow
Solution 4 - IphoneYingView Answer on Stackoverflow