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

4

77

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.

Illuminance answered 20/11, 2011 at 13:13 Comment(2)
If you have idea about "Additional url type properties" usage?Ezzo
I've explained it in the post and also provided code to extra parameters from custom url: 2cupsoftech.wordpress.com/2013/01/08/…Incredulity
R
98

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.

Rapeseed answered 8/10, 2012 at 15:4 Comment(3)
Within the .plist file, the relevant code is: <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>goomzee</string> </array> </dict> </array>Bornu
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>com.iphonebasic.testdemo</string> <key>CFBundleURLSchemes</key> <array> <string>com-iphonebasic-testdemo</string> </array> </dict> </array>Reinforcement
@Mike S. I tried the steps you provided, it fade away when I move from Info.plist to other tab.Abutter
W
29

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

Waltz answered 13/3, 2014 at 8:26 Comment(2)
Wow fantastic explanation on your blog. This saved me about 2 hours. THANK YOU!!Tad
The thing is that AFTER MKB:// there MUST be anything.Mcclelland
H
17

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.

Haimes answered 20/11, 2011 at 13:47 Comment(0)
C
0

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.

Casebound answered 14/8, 2012 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.