IOS app calls built-in applications (SMS, email, browser, MAP, appstore, and call number)

Source: Internet
Author: User

In a program, you can call an application that comes with the system. For example, when I enter the program, I want to directly call Safar to open a webpage. Below is a simple usage:

- (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions: (launchOptions NSDictionary *)
{
Self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
Self.viewcontroller = [[[viewController alloc] initWithNibName: @viewcontroller "bundle:nil] autorelease];
The self. The window. The rootViewController = self. ViewController;
[the self. The window makeKeyAndVisible];

// call safar to open the page
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "http://www.cnblogs.com/foxmin"]].
//// call app store (ellipsis followed by product id and other parameters)
/ / [[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "itms://itunes.apple.com/app/..."]].
/ / [[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "itms-apps://itunes.apple.com/app/"]].
//// call the telephone
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://XXXXX"]];
/ / / / call the SMS
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@" SMS ://XXXXX"]];
/ / / / invoke the Remote
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"remote://XXX"]];

Return YES;
}

For more iPhone application calls and third-party application calls, you can view the iPhone URL scheme. The following lists the parts:

Apple iPhone applicationssafari

Any URL starting with http: // which does not point to maps.google.com or www.youtube.com is sent to Safari:

NSString *stringURL = @"http://wiki.akosma.com/";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Apparently feed: // opens http://reader.mac.com in
Safari.


Maps

URLs starting with http://maps.google.com open up the "maps" application automatically:

NSString *title = @"title";
float latitude = 35.4634;
float longitude = 9.43425;
int zoom = 13;
NSString *stringURL = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@@%1.6f,%1.6f&z=%d", title, latitude, longitude, zoom];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

It seems that maps: // also opens up the Maps application.


Phone

The phone links start with "Tel:" but must not contain spaces or brackets (it can contain dashes and "+" signs, though ):

NSMutableString *phone = [[@"+ 12 34 567 89 01" mutableCopy] autorelease];
[phone replaceOccurrencesOfString:@" " 
                       withString:@"" 
                          options:NSLiteralSearch 
                            range:NSMakeRange(0, [phone length])];
[phone replaceOccurrencesOfString:@"(" 
                       withString:@"" 
                          options:NSLiteralSearch 
                            range:NSMakeRange(0, [phone length])];
[phone replaceOccurrencesOfString:@")" 
                       withString:@"" 
                          options:NSLiteralSearch 
                            range:NSMakeRange(0, [phone length])];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phone]];
[[UIApplication sharedApplication] openURL:url];


SMS

To open the SMS application, just use the SMS: Protocol in your url:

NSString *stringURL = @"sms:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

You can specify a phone number, but apparently not a default text for your message:

NSString *stringURL = @"sms:+12345678901";NSURL *url = [NSURL URLWithString:stringURL];[[UIApplication sharedApplication] openURL:url];

The same restrictions apply as for phone URLs, regarding spaces, brackets and dashes.


Mail

These URLs launch mail and open the compose message controller:

NSString *stringURL = @"sms:+12345678901";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

You can also provide more information, for a customized subject and body texts:

NSString *stringURL = @"mailto:test@example.com";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

You might also omit some information:

NSString *subject = @"Message subject";
NSString *body = @"Message body";
NSString *address = @"test1@akosma.com";
NSString *cc = @"test2@akosma.com";
NSString *path = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@", address, cc, subject, body];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];

For more complex body texts, you might want to use the cfurlcreatestringbyaddingpercentescapes () function, as fig in this page.


YouTube

URLs starting with the http://www.youtube.com open up the "YouTube" application automatically:

NSString *stringURL = @"http://www.youtube.com/watch?v=WZH30T99MaM";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

It also works with this URL (which normally brings the Flash video player used by YouTube ):

NSString *stringURL = @"http://www.youtube.com/v/WZH30T99MaM";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];


ITunes

To open up iTunes, use this URL:

NSString *stringURL = @"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=156093464&id=156093462&s=143441";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];


App Store

Very similar to the iTunes urls:

NSString *stringURL = @"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=294409923&mt=8";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];


Ibooks

(Source: http://akos.ma/aqdr)

NSString *stringURL = @"itms-books:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
NSString *stringURL = @"itms-bookss:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];


Third party applications

Most URL schemes in this list come from app lookup.


Airsharing

Launch the application:

NSString *stringURL = @"airsharing://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];


Alocola

Launch the application:

NSString *stringURL = @"alocola://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];


Appigo notebook

Launch the application:

NSString *stringURL = @"appigonotebook://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];


Appigo todo

Launch the application:

NSString *stringURL = @"appigotodo://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Create a new task:

NSString *template = @"appigotodo://com.example.xyzapp/import?name=%@&note=%@&due-date=%@&priority=%@&repeat=%@";
NSString *name = @"Buy%20some%20milk";
NSString *note = @"Stop%20on%20the%20way%20home%20from%20work.";
NSString *dueDate = @"2009-07-16";
NSString *priority = @"1";
NSString *repeat = @"101";
NSString *stringURL = [NSString stringWithFormat:template, name, note, dueDate, priority, repeat];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];


Duo

Launch the application and pre-populate the update field with your desired tweet/Facebook update. optional: Provide duo with the custom URL and return path to your app to provide the user with a button to return to your app.

NSString *appID = @"Your Apps Name";
NSString *updateInfo = @"The Tweet/Status Update";
NSString *returnScheme = @"Your Apps Return URL Scheme";
NSString *returnPath = @"Your/Apps/Return/Path";
NSString *baseURL = @"duoxx://updateFaceTwit?";
	
NSString *encodedUpdateInfo = [updateInfo stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSString *urlString = [NSString stringWithFormat:@"%@BLappID=%@;BLupdateInfo=%@;BLreturnScheme=%@;BLreturnPath=%@", 
						   baseURL, appID, encodedUpdateInfo, returnScheme, returnPath];

NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];

 


The cartographer

Launch app and add a placemark at given coordinate:


NSString *title = @"Placemark title (optional)";

NSString *summary = @"Placemark description (optional)";

CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(123.0, 12.0);


title = [(id)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)title, NULL, (CFStringRef)@";/?:@&=+$,", kCFStringEncodingUTF8) autorelease];

summary = [(id)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)summary, NULL, (CFStringRef)@";/?:@&=+$,", kCFStringEncodingUTF8) autorelease];


NSString *cartographerURL = [NSString stringWithFormat:@"cartographer://placemark?coordinate=%lf,%lf&title=%@&summary=%@",

        coordinate.latitude, coordinate.longitude, title, summary];


NSURL *url = [NSURL URLWithString:cartographerURL];

[[UIApplication sharedApplication] openURL:url];

Launch app and load either a KML source or a Google My Map:


NSString *sourceURL = @"http://....";

// e.g. http://maps.google.com/maps/ms?ie=UTF8&hl=en&msa=0&msid=208320711678395936256.00046bbcfdcd1f3ebf64b&z=5


// Optional:

MKCoordinateRegion region = ...;

sourceURL = [sourceURL stringByAppendingFormat:@"&ll=%lf,%lf&spn=%lf,%lf",

              region.center.latitude, region.center.longitude, region.span.latitudeDelta, region.span.longitudeDelta];


NSURL *url = [NSURL URLWithString:[sourceURL stringByReplacingOccurrencesOfString:@"http://" withString:@"cartographer://"]];

[[UIApplication sharedApplication] openURL:url];



ChatCo


NSString *stringURL = @"irc://irc.example.domain/roomName";

NSURL *url = [NSURL URLWithString:stringURL];

[[UIApplication sharedApplication] openURL:url];

NSString *stringURL = @"irc://irc.example.domain/Nickname@roomName";

NSURL *url = [NSURL URLWithString:stringURL];

[[UIApplication sharedApplication] openURL:url];

NSString *stringURL = @"irc://irc.example.domain/Nickname!Realname@roomName";

NSURL *url = [NSURL URLWithString:stringURL];

[[UIApplication sharedApplication] openURL:url];



Related Article

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.