iOS 拨打电话的三种方式


例:代码如下:

#import"ViewController.h"


#define DD_WIDTH  self.view.bounds.size.width

#define DD_HEIGHT45.f


@implementation ViewController {

   UITextField *telTextField;

}


- (void)viewDidLoad {

    [superviewDidLoad];

   telTextField = [UITextField new];

    [telTextField setFrame:CGRectMake(0.f80.fDD_WIDTHDD_HEIGHT)];

    [telTextField setPlaceholder:@"请输入要拨打的号码..."];

    [telTextField setTextColor:[UIColorblackColor]];

    [telTextField setBackgroundColor:[UIColorgrayColor]];

    [telTextField setKeyboardType:UIKeyboardTypeNumberPad];

    [self.viewaddSubview:telTextField];

    

   UIButton *callButton = [UIButton new];

    [callButton setFrame:CGRectMake(0.f145.fDD_WIDTHDD_HEIGHT)];

    [callButton setTitle:@"拨打电话"forState:UIControlStateNormal];

    [callButton setBackgroundColor:[UIColorgrayColor]];

    [callButton addTarget:selfaction:@selector(buttonClick:)forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:callButton];

}

-------------------------------------** 点击时有下列三种方法可选 ** --------------------------------------------------------------

// 1. 会弹出提示,推荐这种

- (void)buttonClick:(UIButton *)click {

   NSString *number = telTextField.text;

   NSMutableString *mutableString = [[NSMutableStringalloc]initWithFormat:@"tel:%@",number];

   UIWebView *webview = [[UIWebViewalloc]init];

    [webview loadRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:mutableString]]];

    [self.view addSubview:webview];

}


// 2. 直接拨打,不弹出提示

//- (void)buttonClick:(UIButton *)click {

//    NSString *number = telTextField.text;

//    NSMutableString *mutableString = [[NSMutableString alloc] initWithFormat:@"tel:%@",number];

//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mutableString]];

//}


// 3. telprompt,也会弹出提示

//- (void)buttonClick:(UIButton *)click {

//    NSString *number = telTextField.text;

//    NSMutableString *mutableString = [[NSMutableString alloc] initWithFormat:@"telprompt://%@",number];

//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mutableString]];

//}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

}

@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值