openURL的使用方法:
view plaincopy toclipboardprint?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appString]];
其中系統的appString有:
view plaincopy toclipboardprint?
1.Map http://maps.google.com/maps?q=Shanghai
2.Email mailto://[email protected]
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 =[addressTextstringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSString*urlText = [NSStringstringWithFormat:@"http://maps.google.com/maps?q=%@",addressText];
NSLog(@"urlText=============== %@", urlText);
[[UIApplicationsharedApplication] openURL:[NSURL URLWithString:urlText]];
}
- (IBAction)openEmail {
//打開mail // Fire off an email to apple support
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"mailto://[email protected]"]];
}
- (IBAction)openPhone {
//撥打電話
// CallGoogle 411
[[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"tel://8004664411"]];
}
- (IBAction)openSms {
//打開短信
// Text toGoogle SMS
[[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"sms://466453"]];
}
-(IBAction)openBrowser {
//打開瀏覽器
// Lanuch any iPhone developers fav site
[[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"http://itunesconnect.apple.com"]];
}