IOS拨打电话功能的实现
来源:互联网 发布:javascript call是什么 编辑:程序博客网 时间:2024/04/29 05:08
IOS拨打电话功能的实现
简介:本事例是点击一个UItableviewcell中的拨打电话按钮,所以电话号码的值是从model中获取,其中_dataArray为接口获取cell内容的数组。
1、在添加cell的时候,给拨打电话按钮添加事件,并添加Tag值(方便获取数组下标,从而得到没个cell中内容对应的电话号码字段)
[cell.phoneButton addTarget:self action:@selector(callPhoneAction:) forControlEvents:UIControlEventTouchUpInside];
cell.phoneButton.tag=500+indexPath.section;
2、在创建点击事件之前需要添加事先声明个电话号码NSstring的全局变量,并添加UIActionSheetDelegate代理方法,我们需要用到UIActionSheet的代理事件
//添加全局电话号码
NSString *_mobileStr;
在接口协议中添加UIActionSheetDelegate
@interface MyHotalController ()<UITableViewDataSource,UITableViewDelegate,UIActionSheetDelegate>
3、添加拨打电话按钮的事件
#pragma mark cell中的拨打电话按钮事件
-(void)callPhoneAction:(UIButton *)btn{
MyHotalModel *model=_dataArray[btn.tag - 500];
_mobileStr=model.mobile;
UIActionSheet *actionSheet=[[UIActionSheet alloc] initWithTitle:@"是否拨打电话?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:_mobileStr otherButtonTitles:nil];
actionSheet.tag=300;
actionSheet.actionSheetStyle=UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
}
4、实现UIActionSheetDelegate代理方法,点击电话号码按钮时,检测设备是否支付通话,不支持则提示,支持就拨打电话
#pragma mark - UIActionSheetDelegate代理方法
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==0&&actionSheet.tag==300) {
BOOL flag=[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_mobileStr]]];
if(!flag){
UIAlertView *callalert=[[UIAlertView alloc]initWithTitle:@"亲,你的设备不支持通话功能哦" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[callalert show];
}
else{
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_mobileStr]]];
}
}
}
- iOS 拨打电话功能的实现
- iOS 拨打电话功能的实现
- IOS拨打电话功能的实现
- iOS拨打电话功能的实现
- iOS中实现拨打电话功能
- iOS 拨打电话功能
- iOS拨打电话功能
- Android 实现拨打电话功能
- android拨打电话功能实现
- Android 实现拨打电话功能
- Android实现拨打电话功能
- iOS 点击按钮实现拨打电话,发送短信功能
- 【Android】Android开发初学者实现拨打电话的功能,拨打电话app小demo实现
- iPhone 应用中实现拨打电话功能的代码
- 实例解说android实现拨打电话的功能
- iPhone 应用中实现拨打电话功能的代码
- Oc 拨打电话和发短信功能的实现
- iOS拨打电话的方式
- android动画
- 归档和解档
- 拦截器Interceptor的使用
- dbcc page解析行数据
- scala memched 集成
- IOS拨打电话功能的实现
- 关于add苹果私有库后无法显示.h的问题
- 图书详细信息接口调用代码实现
- 18 4Sum
- RotateAnimation
- 【九周年活动】我和高胖有个约会~!
- 为什么清除浮动
- XML DTD和XML Schema
- 1089~1096 (练习输入输出的8个题目)