一點一滴,編程人生

            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 閱讀(604) 評論(0)  編輯  收藏 所屬分類: iphone
          主站蜘蛛池模板: 邢台县| 耿马| 泽普县| 西充县| 子洲县| 稷山县| 新乡市| 工布江达县| 乌兰县| 蒙阴县| 临颍县| 青海省| 金坛市| 靖安县| 清丰县| 平果县| 仙桃市| 吉水县| 开封县| 依兰县| 藁城市| 罗甸县| 老河口市| 垫江县| 宁波市| 房产| 自治县| 福建省| 玉屏| 蓬安县| 托克托县| 沙雅县| 黄山市| 绵竹市| 尚志市| 临澧县| 日喀则市| 海兴县| 宜阳县| 富民县| 永宁县|