Launching other apps within an iPhone application

Source: Internet
Author: User
Posted on October 16,200 8 by rosydney aiglstorfer "href =" http://iphonedevelopertips.com/author/rodney/ "> rosydney aiglstorfer
In posts in cocoa "rel =" category tags "href =" http://iphonedevelopertips.com/category/cocoa "> cocoa

 

In an earlier
Post
I talked about how to launch the browser from within an iPhone
Application UsingUIApplication:openURL:
Method.

It is also possible to use this same technique to launch other
Applications on the iPhone that are very useful.

Examples of some of the key applications that you can launch via URL
Are:

  • Launch the browser (see
    Earlier post
    )
  • Launch Google Maps
  • Launch Apple Mail
  • Dial a phone number
  • Launch the SMS Application
  • Launch the browser
  • Launch the appstore

 

Launch Google Maps

The URL string for launching Google maps with a special keyword
Follows this structure:

http://maps.google.com/maps?q=${QUERY_STRING}

The only trick to this is to ensure that the value for$ {QUERY_STRING}
Is properly URL encoded. Here is a quick example of how you wowould
Launch Google Maps for a specific address:

1
2
3
4
5
6
7
8
9
10
11
// Create your query ...
NSString* searchQuery = @"1 Infinite Loop, Cupertino, CA 95014";
 
// Be careful to always URL encode things like spaces and other symbols that aren't URL friendly
searchQuery = [addressText stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
 
// Now create the URL string ...
NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", searchQuery];
 
// An the final magic ... openURL!
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
Launch Apple Mail

Also very useful, is the ability to enable a user to quickly send
Email by launching the email client in Compose mode and the address
Already filled out. The format of this URI shoshould be familiar to anyone
That has done any work with HTML and looks like this:

mailto://${EMAIL_ADDRESS}

For example, here we are opening the email application and filling
The "to:" addressInfo@iphonedevelopertips.com
:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://info@iphonedevelopertips.com"]];
Dial a phone number (iPhone only)

You can useopenURL:
To dial a phone number. One
Advantage this has over other URLs that launch applications, is that
Dialer will return control back to the application when the user hits
The "End call" button.

Anyone familiar with j2-or WML will find this URL scheme familiar:

tel://${PHONE_NUMBER}

Here is an example of how we wowould dial the number (800) 867-5309:

1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];

Note
When providing an international number you will
Need to include the country code.

Launch the SMS Application

Also not supported by the iPod Touch, is the ability to quickly setup
The SMS client so that your users can quickly send a text message. It
Is also possible to provide the body of the text message.

The format looks like this:

sms:${PHONENUMBER_OR_SHORTCODE}

Note:
Unlike other URLs, an sms url doesn' t use
"//" Syntax. If you add these it will assume it is part of the phone
Number which is not.

1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:55555"]];

Note:
According to the official SMS specification,
You shoshould be able to send a body as well as the phone number
Including "? Body = "parameter on the end of the URL... Unfortunately Apple
Doesn't seem to support this standard.

Launching the appstore

Finally, it is worth noting that you can launch the appstore and have
The "buy" page of a specific application appear. To do this, there is
No special URL scheme. All you need to do is open up iTunes to
Application you want to launch; right-click on the application icon
The top left of the page; and selectCopy iTunes store URL
.

The URL will look something like this:

http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8

Launching the appstore URL is exactly the same as you wowould launch
The browser. Using the link abve, here is an example of how we wowould
Launch the appstore:

1
2
NSURL *appStoreUrl = [NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8"];
[[UIApplication sharedApplication] openURL:appStoreUrl];
Share with other IOs developers:

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //

 

Http://iphonedevelopertips.com/cocoa/launching-the-browser-from-within-an-iphone-application.html

 

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //

 

It depends on the app you wish to launch. Some
Of them register URLs that let you launch links like iTunes: // and
Like. Check this out: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StandardBehaviors/StandardBehaviors.html#//apple_ref/doc/uid/TP40007072-CH4-SW7

The important section is the one entitled "implementing custom URL
Schemes ".

Edit: Here's a link to a website that catalogs the varous URLs
Existing apps: http://handleopenurl.com/
.

 

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //

 

Http://stackoverflow.com/questions/3443346/can-an-ipad-app-directly-launch-another-app

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.