標籤: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&mt=8
程式碼範例:
NSURL*appStoreUrl =[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&amp;mt=8"];
[[UIApplication sharedApplication] openURL:appStoreUrl];