Check If Custom URL Scheme Is Defined
Custom URL Schemes are the Apple approved way for one application to communicate with another. For example, you can launch the phone application to make a call using the custom URL tel://. Likewise, you can call a third party (non Apple) application using a custom URL, and similarly, other applications call invoke your app if you define a custom URL.
If you plan to call another application via a custom URL scheme on iOS, here a quick tip to check if a specific URL scheme is defined. The two examples below show the code for creating an NSURL object with the destination URL scheme and using the shared application instance to verify if the URL can be opened:
// If Facebook application installed if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) { do something... } // If ebay application installed if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"ebay://"]]) { do something... }
There are no restrictions on who can define what custom URL. For example, fb:// is not necessarily limited to Facebook, so this process is not entirely foolproof. From what I’ve read, Apple does not define the process for determining which application will be called if more than one app has registered the same URL.
Here are a few posts on getting started with Custom URL Schemes:
- Launching An Application via a Custom URL Scheme
- Launching Other Apps within an iPhone Application
- Launching Other Apps within an iPhone Application (Part 2)