IOS openURL 運行其他的應用程式

來源:互聯網
上載者:User

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://myname@google.com
  3. Tel tel://10086
  4. 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?

  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://devprograms@apple.com"]];
  5. }

- (IBAction)openEmail {
//開啟mail // Fire off an email to apple support 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];
} 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"]]; 
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.