在iOS開發中,經常需要調用其它App,如撥打到電話、發送郵件等。UIApplication:openURL:方法是實現這一目的的 ##轉

來源:互聯網
上載者:User

標籤:blog   class   c   code   tar   ext   

源地址:http://blog.csdn.net/lengshengren/article/details/16339409

 

在iOS開發中,經常需要調用其它App,如撥打到電話、發送郵件等。UIApplication:openURL:方法是實現這一目的的最簡單方法,該方法一般通過提供的url參數的模式來調用不同的App。

通過openURL方法可以調用如下應用:

  • 調用Google地圖(Google Maps)
  • 調用郵件用戶端(Apple Mail)
  • 撥號(Phone Number)
  • 調用簡訊(SMS)
  • 呼叫瀏覽器(Safari Browser)
  • 調用市集(AppStore)

 

調用Google地圖(Google Maps)

URL模式:http://maps.google.com/maps?q=<strong>${QUERY_STRING}</strong>

程式碼範例:

NSString* searchQuery [email protected]"1 Infinite Loop, Cupertino, CA 95014";
searchQuery =[addressText stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString* urlString =[NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", searchQuery];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];

 

 

調用郵件用戶端(Apple Mail)

URL模式:mailto://<strong>${EMAIL_ADDRESS}</strong>

程式碼範例:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];

 

 

撥號(Phone Number)

URL模式:tel://<strong>${PHONE_NUMBER}</strong>

程式碼範例:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];

 

 

調用簡訊(SMS)

URL模式:sms:<strong>${PHONENUMBER_OR_SHORTCODE}</strong>

程式碼範例:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:10086"]];

 

 

呼叫瀏覽器(Safari Browser)

程式碼範例:

NSURL*url =[NSURL URLWithString:@"http://eyecm.com"];
[[UIApplication sharedApplication] openURL:url];

 

 

調用市集(AppStore)

URL模式:http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&amp;mt=8

程式碼範例:

NSURL*appStoreUrl =[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&amp;amp;mt=8"];
[[UIApplication sharedApplication] openURL:appStoreUrl];

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.