打电话功能的实现

这周的工作中遇到了实现点击按钮打电话的功能,为了能更加的熟练掌握,我就整理了一下打电话功能的,希望能在提高自己的同时,帮助到我们的初学者
`#import “ViewController.h”

@interface ViewController ()
@property(nonatomic,strong)NSString *str;
@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    self.str=@”13333333333”;
    UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(50, 100, 100 ,80)];
    button.backgroundColor=[UIColor redColor];
    [button addTarget:self action:@selector(CallPhone) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

}
打电话按钮的的方法 点击button直接拨打电话
//-(void)CallPhone
//{
// //调用拨打电话按钮
NSString *tel= [NSString stringWithFormat:@”tel:%@”,self.phoneNum];
// NSString *tel=@”tel:15736709059”;
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
//}

//打电话的方法 带有提示框的打电话点击提示框的确定才能拨打电话

//-(void)CallPhone
//{
//
// if (self.str) {
// UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@”拨打电话” message:self.str delegate:self cancelButtonTitle:@”取消” otherButtonTitles:@”确定”, nil];
// [alertView show];
// }
//
//
//}
//- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
//{
// if (alertView.cancelButtonIndex!=buttonIndex) {
// //调用拨打电话按钮
// NSString *tel= [NSString stringWithFormat:@”tel:%@”,self.str];
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
// }
//}

//iOS9中的新特新,带有提示框的拨打电话的方法
-(void)CallPhone
{
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@”打电话” message:self.str preferredStyle:UIAlertControllerStyleAlert];
//cancel这个Style是取消按钮
[alert addAction:[UIAlertAction actionWithTitle:@”取消” style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//点击按钮的响应事件
}]];
//
// UIAlertActionStyleDefault 自定义的按钮的点击方式
// UIAlertActionStyleCancel, 取消按钮的点击方式
// UIAlertActionStyleDestructive 有警告性质的按钮的点击方式 设置这个的时候按钮是红色的
//在style中Default是默认情况下的样式
[alert addAction:[UIAlertAction actionWithTitle:@”确定” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// //点击按钮的响应事件
NSString *tel=[NSString stringWithFormat:@”tel:%@”,self.str];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];

}]];
//弹出提示框的方法
[self presentViewController:alert animated:true completion:nil];

}

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

@end
`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值