openURL的使用方法:
view plaincopy
to clipboardprint?
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appString]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appString]];
其中系統的appString有:
view plaincopy
to clipboardprint?
- Map http://maps.google.com/maps?q=Shanghai
- Email mailto://myname@google.com
- Tel tel://10086
- Msg sms://10086
Map http://maps.google.com/maps?q=Shanghai
Email mailto://myname@google.com
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
開啟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]];
- }
- (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]];
}
view plaincopy
to clipboardprint?
- - (IBAction)openEmail {
- //開啟mail
- // Fire off an email to apple support
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];
- }
- (IBAction)openEmail {
//開啟mail // Fire off an email to apple support
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];
} view
plaincopy to clipboardprint?
- - (IBAction)openPhone {
- //撥打到電話
- // Call Google 411
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];
- }
- (IBAction)openPhone {
//撥打到電話
// 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"]];
- }
- (IBAction)openSms {
//開啟簡訊
// 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"]];
- }
-(IBAction)openBrowser {
//開啟瀏覽器
// Lanuch any iPhone developers fav site
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunesconnect.apple.com"]];
}