在iOS开发中,经常需要调用其它App,如拨打电话、发送邮件等。UIApplication:openURL:方法是实现这一目的的 ##转

源地址:http://blog.csdn.net/lengshengren/article/details/16339409

 

iOS开发中,经常需要调用其它App,如拨打电话、发送邮件等。UIApplication:openURL:方法是实现这一目的的最简单方法,该方法一般通过提供的url参数的模式来调用不同的App。

通过openURL方法可以调用如下应用:

  • 调用谷歌地图(Google Maps)
  • 调用邮件客户端(Apple Mail)
  • 拨号(Phone Number)
  • 调用短信(SMS)
  • 调用浏览器(Safari Browser)
  • 调用应用商店(AppStore)

 

调用谷歌地图(Google Maps)

URL模式:http://maps.google.com/maps?q=<strong>${QUERY_STRING}</strong>

代码示例:

NSString* searchQuery =@"1 Infinite Loop, Cupertino, CA 95014";
searchQuery =[addressText stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString* urlString =[NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", searchQuery];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];

 

 

调用邮件客户端(Apple Mail)

URL模式:mailto://<strong>${EMAIL_ADDRESS}</strong>

代码示例:

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

 

 

拨号(Phone Number)

URL模式:tel://<strong>${PHONE_NUMBER}</strong>

代码示例:

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

 

可以跳转回来

NSString *phoneNum =[NSString stringWithFormat:@"%@",_model.contactWay];// 电话号码
NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];
if ( !phoneCallWebView ) {
phoneCallWebView = [[UIWebView alloc]initWithFrame:CGRectZero];// 这个webView只是一个后台的控件 不需要add到页面上来 效果跟方法一样 但是这个方法是合法的
}
[phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];

 

 

调用短信(SMS)

URL模式:sms:<strong>${PHONENUMBER_OR_SHORTCODE}</strong>

代码示例:

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

 

 

调用浏览器(Safari Browser)

代码示例:

NSURL*url =[NSURL URLWithString:@"http://eyecm.com"];
[[UIApplication sharedApplication] openURL:url];

 

 

调用应用商店(AppStore)

URL模式:http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&amp;mt=8

代码示例:

NSURL*appStoreUrl =[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&amp;amp;mt=8"];
[[UIApplication sharedApplication] openURL:appStoreUrl];

posted @ 2014-05-20 11:21  Qiang zi  阅读(291)  评论(0编辑  收藏  举报