openURL的使用方法:
view plaincopy to clipboardprint?
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appString]];
其中系統的appString有:
view plaincopy to clipboardprint?
- Map http://maps.google.com/maps?q=Shanghai
- Email mailto://[email protected]
- Tel tel://10086
- Msg sms://10086
Email mailto://[email protected]
Tel tel://10086
Msg sms://10086
除此之外,還可以自己定義URL,方法如下:
view plaincopy to clipboardprint?- 打開info.plist,添加一項URL types
- 展開URL types,再展開Item1,將Item1下的URL identifier修改爲URL Scheme
- 展開URL Scheme,將Item1的內容修改爲myapp
- 其他程序可通過myapp://訪問此自定義URL
參考資料:
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo}
http://iphonedevelopertips.com/cocoa/launching-other-apps-within-an-iphone-application.html
openURL能幫助你運行Maps,SMS,Browser,Phone甚至其他的應用程序。這是Iphone開發中我經常需要用到的一段代碼,它僅僅只有一行而已。
view plaincopy to clipboardprint?- - (IBAction)openMaps {
- //打開地圖
- NSString *addressText = @"beijing";//@"1 Infinite 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]];
- }
//打開地圖
NSString *addressText = @"beijing";
//@"1 Infinite 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]];
}
view plaincopy to clipboardprint?
- - (IBAction)openEmail {
- //打開mail
- // Fire off an email to apple support
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];
- }
//打開mail // Fire off an email to apple support
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];
} view plaincopy to clipboardprint?
- - (IBAction)openPhone {
- //撥打電話
- // Call Google 411
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];
- }
//撥打電話
// Call Google 411
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];
} view plaincopy to clipboardprint?
- - (IBAction)openSms {
- //打開短信
- // Text to Google SMS
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://466453"]];
- }
//打開短信
// Text to Google SMS
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://466453"]];
}
view plaincopy to clipboardprint?
- -(IBAction)openBrowser {
- //打開瀏覽器
- // Lanuch any iPhone developers fav site
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunesconnect.apple.com"]];
- }
//打開瀏覽器
// Lanuch any iPhone developers fav site
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunesconnect.apple.com"]];
}