openURL的使用(iOS調用系統電話、瀏覽器、地圖、郵件等)

今天遇見一行代碼實現打開一個網頁,比起印象裏的UIWebView控件實現簡單很多,很容易使用而且,經過真機測試卻是很方便使用,在網上又搜索了一點相關資料:


代碼段:[[UIApplication sharedApplication] openURL:url];


其中系統的url有:
1.Map    http://maps.google.com/maps?q=Shanghai  
2.Email  mailto://[email protected]  
3.Tel    tel://10086  
4.Msg    sms://10086  


  1. - (IBAction)openMaps {  
  2. //打開地圖   
  3. NSString*addressText = @"beijing";  
  4. //@"1Infinite Loop, Cupertino, CA 95014";   
  5. addressText =[addressText stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];   
  6.   
  7. NSString  *urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",addressText];   
  8. NSLog(@"urlText=============== %@", urlText);  
  9. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];  
  10. }  
  11.   
  12. - (IBAction)openEmail {  
  13. //打開mail // Fire off an email to apple support  
  14. [[UIApplication sharedApplication]openURL:[NSURL   URLWithString:@"mailto://[email protected]"]];  
  15. }   
  16.   
  17. - (IBAction)openPhone {  
  18.   
  19. //撥打電話  
  20. // Call Google 411  
  21. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];  
  22. }   
  23.   
  24. - (IBAction)openSms {  
  25. //打開短信  
  26. // Text toGoogle SMS  
  27. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://10086"]];  
  28. }  
  29.   
  30. -(IBAction)openBrowser {  
  31. //打開瀏覽器  
  32. // Lanuch any iPhone developers fav site  
  33. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://blog.csdn.net/duxinfeng2010"]];  
  34. }  


參考 http://www.cocoachina.com/bbs/read.php?tid=73570&page=3


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章