Tuesday, March 13, 2012

Launch SMS, Phone, Email, Google Maps & Browser apps from xcode:

Launching the above mentioned apps from the code has never been easier...

1) Open default Phone app in iPhone:

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

*) To launch the app after the user hangs up.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://9786663663"]];

*) To check if the iOS device supports making a call.

UIDevice *device = [UIDevice currentDevice];
if ([[device model] isEqualToString:@"iPhone"] ) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@", self.phoneTest]]];
} else {
UIAlertView *Notpermitted=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[Notpermitted show];
[Notpermitted release];
}

2) Open default SMS app in iPhone:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://9786663663"]];

3) Open default Email app in iPhone:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://apple@apple.com"]];

4) Open default Maps app in iPhone:

NSString* addressText = @"1 Infinite Loop, Cupertino, CA 95014";
// URL encode the spaces
addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", addressText];
// lets throw this text on the log so we can view the url in the event we have an issue
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];

5) Open default Browser app in iPhone:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];

No comments:

Post a Comment