Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 554
openfrog Avatar asked Nov 20 '11 13:11

openfrog


People also ask

How do I register a URL scheme?

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.

How do I find the URL scheme of an app?

Get the Package Name of an Android AppGo to the Play store, find the app and view its page. Copy the URL from the browser address bar. Make a note of this as the "Android Fallback URL." You'll see a parameter called "id" followed by an equal sign (=).

What is URL scheme iOS?

LAST UPDATED: MAY 31, 2022. URL schema is used as an identifier in launching applications and performing a set of commands in iOS devices. The schema name of a URL is the first part of a URL. (e.g. schemaname:// ). For web pages, the schemas are usually http or https.


2 Answers

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.

like image 61
Mike S. Avatar answered Sep 20 '22 15:09

Mike S.


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

like image 36
Mike Gledhill Avatar answered Sep 19 '22 15:09

Mike Gledhill