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]];
}
- (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"]];
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步