New-Krish-15

 We can open system applications or other iOS apps from our iOS application code. in order to do this we need to use a technique called URL schemes we can create our own URL schemes.

How to check whether the app is installed in iOS device or not?

Sometimes you may want to check if a specific app is installed on the device, in case you use custom URL scheme. If you know the apps URL scheme you can find the app installed or not by this code :

BOOL isAppInstalled=[[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@”APP-URL-Scheme”]]; 
if(isAppInstalled) {
// app launching code
}else {
 // app download prompting code
}
 

Sending a Mail  from iOS App

The mailto scheme is used to launch the Mail application and open the email compose sheet. When specifying a mailto URL, you must provide the target email address. The following examples show strings formatted for Safari and for native iOS applications.

  • HTML link:
    <a href=”mailto:krish@way2ios.com”>Krish</a>
  • Native application code:
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:
    @mailto:krish@way2ios.com]];

You can also include a subject field, a message, and multiple recipients in the To, Cc, and Bcc fields. (In iOS, the from attribute is ignored.) The following example shows a mailto URL that includes several different attributes:

mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!

Making a Phone Call from iOS app

The tel URL scheme is used to launch the Phone application and initiate dialing of the specified phone number. Tapping a telephone link on a webpage displays an alert asking if the user really wants to dial the phone number and initiates dialing if the user accepts. In a native application, opening a URL with the telscheme initiates dialing without further prompting from the user.You can specify phone links explicitly in both web and native iOS applications using the tel URL scheme. The following examples show the strings formatted for Safari and for a native application:

  • HTML link:
    <a href=”tel:1-408-555-5555″>1-408-555-5555</a>
  • Native application code:
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:
    @”tel:1-408-555-5555″]];

To prevent users from maliciously redirecting phone calls or changing the behavior of a phone or account, the Phone application supports most, but not all, of the special characters in the tel scheme. Specifically, if a URL contains the * or # characters, the Phone application does not attempt to dial the corresponding phone number. If your application receives URL strings from the user or an unknown source, you should also make sure that any special characters that might not be appropriate in a URL are escaped properly. For native applications, use the stringByAddingPercentEscapesUsingEncoding: method of NSString to escape characters, which returns a properly escaped version of your original string.

In Safari on iOS, telephone number detection is on by default. However, if your webpage contains numbers that can be interpreted as phone numbers, but are not phone numbers, you can turn off telephone number detection. You might also turn off telephone number detection to prevent the DOM document from being modified when parsed by the browser. To turn off telephone number detection in Safari on iOS, use the format-detectionmeta tag as follows:

<meta name = “format-detection” content = “telephone=no”>

Sending an SMS from the iOS App

The sms scheme is used to launch the Text application. The format for URLs of this type is “sms:<phone>”, where <phone> is an optional parameter that specifies the target phone number of the SMS message. This parameter can contain the digits 0 through 9 and the plus (+), hyphen (-), and period (.) characters. The URL string must not include any message text or other information.

The following examples show strings formatted for Safari and for native applications.

  • HTML links:
  • <a href=”sms:”>Launch Text Application</a>
    <a href=”sms:1-408-555-1212″>New SMS Message</a>
    • Native application URL strings:
  • [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@”sms:”]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:
    @”sms:1-408-555-1212″]];

Opening Maps App

The maps URL scheme is used to show geographical locations and to generate driving directions between two points. If your application includes address or location information, you can use map links to forward that information to the Maps application on iOS and the Google Maps website on other platforms.

Unlike some schemes, map URLs do not start with a “maps” scheme identifier. Instead, map links are specified as regular http links but are targeted at the Google Maps servers. The following examples show the strings you would use in Safari and in a native application to show a map of the city of Cupertino, California.

  • HTML link:
    <a href=http://maps.google.com/maps?q=india>India</a>
  • Native application code:
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:
    @http://maps.google.com/maps?q=india]];

The following examples show the strings you would use to provide driving directions between San Francisco and Cupertino:

  • HTML link:
    <a href=”http://maps.google.com/maps?daddr=San+Francisco,+CA&saddr=cupertino”>Directions</a>
  • Native application string:
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:
    @”http://maps.google.com/maps?daddr=San+Francisco,+CA&saddr=cupertino”]];

Opening YouTube App

The YouTube URL scheme is used to launch the YouTube application or connect to the YouTube website to play the specified video. If your application links to YouTube content, you can use this scheme to play videos from your application.

Unlike some schemes, YouTube URLs do not start with a “youtube” scheme identifier. Instead, they are specified as regular http links but are targeted at the YouTube server. The following examples show the basic strings you would use in Safari and in an application to show a YouTube video. In each example, you would need to replace the VIDEO_IDENTIFIER value with the identifier of the video you wanted to display:

  • HTML links:
    <a href=”http://www.youtube.com/watch?v=VIDEO_IDENTIFIER”>Play Video</a>
    <a href=”http://www.youtube.com/v/VIDEO_IDENTIFIER”>Play Video</a>
  • Native application URL strings:
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:
    @”http://www.youtube.com/watch?v=VIDEO_IDENTIFIER”]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:
    @”http://www.youtube.com/v/VIDEO_IDENTIFIER”]];

Opening iTunes App

The iTunes URL scheme is used to link to content on the iTunes Music Store. The iTunes URL format is complicated to construct, so you create it using an online tool called iTunes Link Maker. The tool allows you to select a country destination and media type, and then search by song, album, or artist. After you select the item you want to link to, it generates the corresponding URL.

The following examples show the strings you would use in Safari and in a native iOS application to link to a song on the iTunes Music Store. The HTML example includes the complete link returned by the iTunes Link Maker tool, which includes a link to any appropriate artwork for the target link.

  • HTML link:
    <a href=”http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=156093464&id=156093462&s=143441″>
    <img height=”15″ width=”61″ alt=”Randy Newman – Toy Story
    – You&#39;ve Got a Friend In Me” src=”http://ax.phobos.apple.com.edgesuite.net/images/
    badgeitunes61x15dark.gif”></img>
    </a>
  • Native application code:
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:
    @”http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=156093464&id=156093462&s=143441″]];

Opening App Store App

To do this, there is no special URL scheme. All you need to do is open up iTunes to the application you want to launch; right-click on the application icon at the top left of the page; and select Copy iTunes Store URL .

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@”Copied iTunes Store URL“]];

openURL: returns a boolean that can be used to determine whether the device is able to handle the URL.

Opening iBooks App

NSString *stringURL = @”itms-books:”; NSURL *url = [NSURL URLWithString:stringURL]; [[UIApplication sharedApplication] openURL:url];
For more info refer<a href="https://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html"> iOS documentation.</a>

Thanks
  • Daniel Pifko

    Have you discovered a way to check whether the app is installed in iOS device, using HTML/HTML5?

    Thanks,

    Daniel

  • Si

    Has anyone been able to find the scheme to launch the Camera?
    Thanks.

  • How about the “photos” app?

    • We can’t show the photos app with url’s schema, but we can store photos in to the gallery.

  • Mark

    Hi, just wanted to tell you, I loved this article. It was inspiring.
    Keep on posting!