---
title: "新风作浪博客学习(十八)openURL的使用(iOS调用系统电话、浏览器、地图、邮件等) ."
author: "android_zhang"
date: "2013-06-08T09:19:15Z"
tags: ["iOS"]
categories: ["移动开发"]
slug: "openurl-ios"
draft: false
lastmod: "2013-01-20T13:25:16Z"
id: 1772711
url: "https://android-zhang.iteye.com/blog/1772711"
---

今天遇见一行代码实现打开一个网页，比起印象里的UIWebView控件实现简单很多，很容易使用而且，经过真机测试却是很方便使用,在网上又搜索了一点相关资料：




代码段： openURL:url];




其中系统的url有：
1.Map    http://maps.google.com/maps?q=Shanghai  
2.Email  mailto://myname@google.com  
3.Tel    tel://10086  
4.Msg    sms://10086  



```java
- (IBAction)openMaps {
//打开地图 
NSString*addressText = @"beijing";
//@"1Infinite Loop, Cupertino, CA 95014"; 
addressText =[addresstext stringbyaddingpercentescapesusingencoding:nsasciistringencoding]; 

NSString  *urlText = [nsstring stringwithformat:@"http://maps.google.com/maps?q=%@",addressText]; 
NSLog(@"urlText=============== %@", urlText);
[[uiapplication sharedapplication] openURL:[nsurl urlwithstring:urltext]];
}

- (IBAction)openEmail {
//打开mail // Fire off an email to apple support
[[uiapplication sharedapplication]openURL:[nsurl   urlwithstring:@"mailto://devprograms@apple.com"]];
} 

- (IBAction)openPhone {

//拨打电话
// Call Google 411
[[uiapplication sharedapplication] openURL:[nsurl urlwithstring:@"tel://10086"]];
} 

- (IBAction)openSms {
//打开短信
// Text toGoogle SMS
[[uiapplication sharedapplication] openURL:[nsurl urlwithstring:@"sms://10086"]];
}

-(IBAction)openBrowser {
//打开浏览器
// Lanuch any iPhone developers fav site
[[uiapplication sharedapplication] openURL:[nsurl urlwithstring:@"http://blog.csdn.net/duxinfeng2010"]];
}
```



参考 http://www.cocoachina.com/bbs/read.php?tid=73570&page=3