一點一滴,編程人生

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            69 隨筆 :: 0 文章 :: 25 評論 :: 0 Trackbacks

          openURL的使用方法:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appString]];
          其中系統的appString有:
          1.Map http://maps.google.com/maps?q=Shanghai 
          2.Email mailto://myname@google.com 
          3.Tel tel://10086 
          4.Msg sms://10086 


          openURL能幫助你運行Maps,SMS,Browser,Phone甚至其他的應用程序。這是iPhone開發中我經常需要用到的一段代碼,它僅僅只有一行而已。

          //打開地圖

          - (IBAction)openMaps {
          NSString*addressText = @"beijing"; //@"1Infinite Loop, Cupertino, CA 95014"; 
          addressText =[addressText stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; 
          NSString*urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",addressText]; 
          NSLog(@"urlText=============== %@", urlText); 
          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
          }

          //打開mail

          - (IBAction)openEmail { 

          [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];

           }


          //撥打電話 

          - (IBAction)openPhone {

           [[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"tel://8004664411"]]; 

          }

          使用這種方式撥打電話時,當用戶結束通話后,iphone界面會停留在電話界面。
          用如下方式,可以使得用戶結束通話后自動返回到應用:
          UIWebView*callWebview =[[UIWebView alloc] init];
          NSURL *telURL =[NSURL URLWithString:@"tel:10086"];// 貌似tel:// 或者 tel: 都行
          [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
          //記得添加到view上
          [self.view addSubview:callWebview];

           還有一種私有方法:(可能不能通過審核)
          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://10086"]];


          //打開短信

          - (IBAction)openSms { 

          [[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"sms://466453"]];

          }


          //打開瀏覽器

          -(IBAction)openBrowser { 

          [[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"http://itunesconnect.apple.com"]]; 

          }

          posted on 2012-06-13 17:09 writegull 閱讀(605) 評論(0)  編輯  收藏 所屬分類: iphone
          主站蜘蛛池模板: 荆门市| 玉田县| 西平县| 靖远县| 吉木乃县| 荣昌县| 喀什市| 天祝| 丹阳市| 衡阳市| 封开县| 荔波县| 崇左市| 巩义市| 东海县| 大宁县| 班戈县| 顺昌县| 彩票| 美姑县| 扬中市| 神木县| 武穴市| 永清县| 眉山市| 商都县| 丹江口市| 和政县| 崇义县| 临夏县| 晋中市| 金溪县| 宜章县| 平武县| 伊吾县| 靖州| 石景山区| 仙游县| 罗甸县| 台湾省| 剑川县|