URL scheme打开方式
根据第三方应用程序的类型,打开IOS系统应用的方式划分为两种URL Scheme分类
IOS支持的URL Schemes分为以下几类<a href="mailto:[email protected]">John Frank</a>本地应用中
if(![[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"mailto:[email protected]"]] ){ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"无法打开程序" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles: nil] ; [alert show] ; }另外也可以通过to,cc,bcc,subject,body字段来指定邮件的抄送,密送,主题,消息内容。参数值都要经过URL编码处理。
mailto:[email protected][email protected]&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!
<a href="tel:1-408-555-5555">1-408-555-5555</a>本地应用中
if(![[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel:1-408-555-5555"]] ){ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"无法打开程序" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles: nil] ; [alert show] ; }
<meta name = "format-detection" content = "telephone=no">Text links(文本链接)
<a href="sms:">Launch Messages App</a> <a href="sms:1-408-555-1212">New SMS Message</a>本地应用中
if(![[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms:1-408-555-1212"]] ){ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"无法打开程序" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles: nil] ; [alert show] ; }iTunes links(iTunes链接)
<a href="https://itunes.apple.com/cn/app/numbers/id361304891?mt=8">Numbers</a>本地应用中
if(![[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/numbers/id361304891?mt=8"]] ){ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"无法打开程序" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles: nil] ; [alert show] ; }Map links(地图链接)
<a href="http://maps.apple.com/?q=cupertino">Cupertino</a>本地应用
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://maps.apple.com/?q=cupertino"]] ;正确的地图链接格式规则如下
<a href="http://www.youtube.com/watch?v=xNsGNlDb6xY">iPhone5</a> <a href="http://www.youtube.com/v/xNsGNlDb6xY">iPhone5</a>本地应用程序中
//或 http://www.youtube.com/v/xNsGNlDb6xY if(![[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=xNsGNlDb6xY"]] ){ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"无法打开程序" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles: nil] ; [alert show] ; }
注:描述于IOS6.0下,关于地图协议,在IOS5.X版本使用的地图为Google Map,详情参见IOS5.X对应的开发者文档。
参见:Apple URL Reference
代码: Demo