现在的位置: 首页 > 综合 > 正文

ios应用中调用系统电话、浏览器、地图、邮件等 以及打开其他应用(如qq,msn)

2018年05月16日 ⁄ 综合 ⁄ 共 1522字 ⁄ 字号 评论关闭

iphone调用系统电话、浏览器、地图、邮件等

openURL的使用方法:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appString]];
其中系统的appString有:
1.Map http://maps.google.com/maps?q=Shanghai 
2.Email mailto://myname@google.com 
3.Tel tel://10086 
4.Msg sms://10086 


openURL能帮助你运行Maps,SMS,Browser,Phone甚至其他的应用程序。这是iPhone开发中我经常需要用到的一段代码,它仅仅只有一行而已。

//打开地图

- (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]];
}

//打开mail

- (IBAction)openEmail { 

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

 }

//拨打电话 

- (IBAction)openPhone {

 [[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"tel://8004664411"]]; 

}

//打开短信

- (IBAction)openSms { 

[[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"sms://466453"]];

}

//打开浏览器

-(IBAction)openBrowser { 

[[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"http://itunesconnect.apple.com"]]; 

}

在自己应用中打开其他应用,如yahoo messenger, msn messenger, qq,facebook。

一般apple app运行在沙河里面,不允许相互调用,但是通过rul scheme 可以实现这个功能。

1. 设置url scheme截图如下

   

   xcode4.2 没有URL types 这个选项,你要在Main nib file base name 下面个那个选项里面找到URL types。

   这里面的todolist就是url scheme。

 如果你在模拟器safari 里面打这些字符  todolist:// 只要你运行过一次你的app,就能直接打开了。

2.   常用的url scheme 查询网站是这个:http://handleopenurl.com/  里面可以查到qq的接口。

抱歉!评论已关闭.