一点一滴,编程人生

  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 阅读(574) 评论(0)  编辑  收藏 所属分类: iphone

只有注册用户登录后才能发表评论。


网站导航: