URL scheme打開方式 html
根據第三方應用程序的類型,打開IOS系統應用的方式劃分爲兩種URL Scheme分類 ios
IOS支持的URL Schemes分爲如下幾類<a href="mailto:frank@wwdcdemo.example.com">John Frank</a>本地應用中
if(![[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"mailto:frank@wwdcdemo.example.com"]] ){ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"沒法打開程序" delegate:nil cancelButtonTitle:@"確認" otherButtonTitles: nil] ; [alert show] ; }另外也能夠經過to,cc,bcc,subject,body字段來指定郵件的抄送,密送,主題,消息內容。參數值都要通過URL編碼處理。
mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!
<a href="tel:1-408-555-5555">1-408-555-5555</a>本地應用中
if(![[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel:1-408-555-5555"]] ){ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"沒法打開程序" delegate:nil cancelButtonTitle:@"確認" otherButtonTitles: nil] ; [alert show] ; }
<meta name = "format-detection" content = "telephone=no">Text links(文本連接)
<a href="sms:">Launch Messages App</a> <a href="sms:1-408-555-1212">New SMS Message</a>本地應用中
if(![[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms:1-408-555-1212"]] ){ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"沒法打開程序" delegate:nil cancelButtonTitle:@"確認" otherButtonTitles: nil] ; [alert show] ; }iTunes links(iTunes連接)
<a href="https://itunes.apple.com/cn/app/numbers/id361304891?mt=8">Numbers</a>本地應用中
if(![[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/numbers/id361304891?mt=8"]] ){ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"沒法打開程序" delegate:nil cancelButtonTitle:@"確認" otherButtonTitles: nil] ; [alert show] ; }Map links(地圖連接)
<a href="http://maps.apple.com/?q=cupertino">Cupertino</a>本地應用
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://maps.apple.com/?q=cupertino"]] ;正確的地圖連接格式規則以下
<a href="http://www.youtube.com/watch?v=xNsGNlDb6xY">iPhone5</a> <a href="http://www.youtube.com/v/xNsGNlDb6xY">iPhone5</a>本地應用程序中
//或 http://www.youtube.com/v/xNsGNlDb6xY if(![[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=xNsGNlDb6xY"]] ){ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"沒法打開程序" delegate:nil cancelButtonTitle:@"確認" otherButtonTitles: nil] ; [alert show] ; }
注:描述於IOS6.0下,關於地圖協議,在IOS5.X版本使用的地圖爲Google Map,詳情參見IOS5.X對應的開發者文檔。 git
參見:Apple URL Reference
代碼: Demo github