码迷,mamicode.com
首页 > 移动开发 > 详细

ios中拨打电话的实现

时间:2014-08-17 15:29:22      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:style   color   使用   os   io   for   ar   art   

// 定义点击拨号按钮时的操作 
 
  1. - (void)callAction{   
  2. NSString *number = @"";// 此处读入电话号码  
  3. // NSString *num = [[NSString alloc]initWithFormat:@"tel://%@",number]; //number为号码字符串 如果使用这个方法结束电话之后会进入联系人列表  
  4.    
  5. NSString *num = [[NSString alloc]initWithFormat:@"telprompt://%@",number]; //而这个方法则打电话前先弹框 是否打电话 然后打完电话之后回到程序中 网上说这个方法可能不合法 无法通过审核  
  6. [[UIApplication sharedApplication] openURL:[NSURLURLWithString:num]]; //拨号  
  7. }  


 
// 下面的代码能在应用中添加一个电话按钮,点击即可拨打电话号码。对于 iPhone 开发者还是很有用的。
 
// 添加电话图标按钮 
 
 
 
  1. UIButton *btnPhone = [[UIButtonbuttonWithType:UIButtonTypeRoundedRect]retain];   
  2. btnPhone.frame =CGRectMake(280,10,30,30);   
  3. [btnPhone setBackgroundColor:[UIColor redColor]];  
  4. // 点击拨号按钮直接拨号   
  5. [btnPhone addTarget:self action:@selector(callAction)forControlEvents:UIControlEventTouchUpInside];   
  6. [self.window addSubview:btnPhone];  


 
//  第三种方式打电
 
 
  1. -(void)CallPhone{  
  2. NSString *phoneNum = @"";// 电话号码  
  3. NSURL *phoneURL = [NSURL URLWithString:[NSStringstringWithFormat:@"tel:%@",phoneNum]];    
  4. if ( !phoneCallWebView ) {          
  5. phoneCallWebView = [[UIWebView alloc]initWithFrame:CGRectZero];// 这个webView只是一个后台的容易 不需要add到页面上来 效果跟方法二一样 但是这个方法是合法的  
  6. }   
  7. [phoneCallWebView loadRequest:[NSURLRequestrequestWithURL:phoneURL]];  
  8. }  
 

 

ios中拨打电话的实现,布布扣,bubuko.com

ios中拨打电话的实现

标签:style   color   使用   os   io   for   ar   art   

原文地址:http://www.cnblogs.com/angongIT/p/3917728.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!