在iOS開發(fā)中浮禾,經(jīng)常需要調(diào)用其它App交胚,如撥打電話份汗、發(fā)送郵件等。UIApplication:openURL:方法是實(shí)現(xiàn)這一目的的最簡單方法蝴簇,該方法一般通過提供的url參數(shù)的模式來調(diào)用不同的App杯活。通過openURL方法可以調(diào)用如下應(yīng)用:
調(diào)用谷歌地圖(Google Maps)
調(diào)用郵件客戶端(Apple Mail)撥號(hào)(Phone Number)
調(diào)用短信(SMS)
調(diào)用瀏覽器(Safari Browser)
調(diào)用應(yīng)用商店(AppStore)?
調(diào)用谷歌地圖(Google Maps)URL模式:http://maps.google.com/maps?q=;${QUERY_STRING}
代碼示例:NSString* searchQuery =@"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]];?
調(diào)用郵件客戶端(Apple Mail)URL模式:mailto://;${EMAIL_ADDRESS}代碼示例:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@eyecm.com"]];?
撥號(hào)(Phone Number)URL模式:tel://${PHONE_NUMBER}代碼示例:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]]; 調(diào)用短信(SMS)URL模式:
sms:${PHONENUMBER_OR_SHORTCODE}代碼示例:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:10086"]]; 調(diào)用瀏覽器(Safari Browser)代碼示例:NSURL*url =[NSURL URLWithString:@"http://eyecm.com"];[[UIApplication sharedApplication] openURL:url];?
調(diào)用應(yīng)用商店(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&mt=8"];[[UIApplication sharedApplication] openURL:appStoreUrl];