你可以使用openUrl開啟一些程式,不只是瀏覽器,我們將在下面的例子中示範這些這些應用:
開啟瀏覽器
開啟google map
開啟email
撥號程式
發簡訊程式
開啟appstore
Launch Google Maps
到googlemap的URL格式是:
http://maps.google.com/maps?q=${QUERY_STRING}
你可以更改QUERY_STRING改變位置資訊:
NSString* searchQuery = @"the postion I want to know";
searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", searchQuery]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]];
開啟Apple Mail
格式:
mailto://${EMAIL_ADDRESS}
[[UIApplication
sharedApplication]
openURL:[NSURL
URLWithString:@"mailto://info@iphonedevelopertips.com"]];
撥打到電話(iPhone Only)
格式:
tel://${PHONE_NUMBER}
1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];
發簡訊
格式
sms:${PHONENUMBER_OR_SHORTCODE}
1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:55555"]];
開啟app store
開啟appstore的程式位置,右鍵點擊程式表徵圖擷取url
格式如下:
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8
1 2
NSURL *appStoreUrl = [NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8"]; [[UIApplication sharedApplication] openURL:appStoreUrl];