UIApplication sharedApplication
iOS开发中使用[[UIApplication sharedApplication] openURL:] 加载其它应用
在iOS开发中,经常需要调用其它App,如拨打电话、发送邮件等。UIApplication:openURL:方法是实现这一目的的最简单方法,该方法一般通过提供的url参数的模式来调用不同的App。
通过openURL方法可以调用如下应用:
调用浏览器(Safari Browser)
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http:google.com"]];
调用谷歌地图(Google Maps)
- NSString *addressText = @"7 Hanover Square, New York, NY 10004";
- addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
- NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", addressText];
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
调用邮件客户端(Apple Mail)
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];
拨号(Phone Number)
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://6463777303"]];
调用短信(SMS)
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://466453"]];
调用应用商店(AppStore)
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8"]];