IOS openURL 運行其他的應用程序

openURL的使用方法:

view plaincopy to clipboardprint?

  1. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appString]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appString]];

其中系統的appString有:

view plaincopy to clipboardprint?

  1. Map http://maps.google.com/maps?q=Shanghai
  2. Email mailto://[email protected]
  3. Tel tel://10086
  4. Msg sms://10086
Map http://maps.google.com/maps?q=Shanghai

Email mailto://[email protected] 

Tel tel://10086 

Msg sms://10086

除此之外,還可以自己定義URL,方法如下:

view plaincopy to clipboardprint?
  1. 打開info.plist,添加一項URL types
  2. 展開URL types,再展開Item1,將Item1下的URL identifier修改爲URL Scheme
  3. 展開URL Scheme,將Item1的內容修改爲myapp
  4. 其他程序可通過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?
  1. - (IBAction)openMaps {
  2. //打開地圖
  3. NSString *addressText = @"beijing";//@"1 Infinite Loop, Cupertino, CA 95014";
  4. addressText = [addressText stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
  5. NSString *urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", addressText];
  6. NSLog(@"urlText =============== %@", urlText);
  7. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
  8. }
- (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?
  1. - (IBAction)openEmail {
  2. //打開mail
  3. // Fire off an email to apple support
  4. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];
  5. }
- (IBAction)openEmail {
//打開mail // Fire off an email to apple support 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];
view plaincopy to clipboardprint?
  1. - (IBAction)openPhone {
  2. //撥打電話
  3. // Call Google 411
  4. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];
  5. }
- (IBAction)openPhone {

//撥打電話 
// Call Google 411
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];
view plaincopy to clipboardprint?
  1. - (IBAction)openSms {
  2. //打開短信
  3. // Text to Google SMS
  4. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://466453"]];
  5. }
- (IBAction)openSms {
//打開短信
// Text to Google SMS 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://466453"]]; 
}
view plaincopy to clipboardprint?
  1. -(IBAction)openBrowser {
  2. //打開瀏覽器
  3. // Lanuch any iPhone developers fav site
  4. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunesconnect.apple.com"]];
  5. }
-(IBAction)openBrowser {
//打開瀏覽器 
// Lanuch any iPhone developers fav site
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunesconnect.apple.com"]]; 
}
發佈了26 篇原創文章 · 獲贊 24 · 訪問量 34萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章