iOS撥打電話

iOS 撥打電話常用2中方法,以下是代碼

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong)UITextField *phoneNumTextField;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UITextField *phoneNumTextField = [[UITextField alloc]init];
    phoneNumTextField.center = self.view.center;
    phoneNumTextField.bounds = CGRectMake(10, 0, self.view.bounds.size.width-10, 44);
    phoneNumTextField.layer.borderColor = [UIColor grayColor].CGColor;
    phoneNumTextField.placeholder = @"輸入電話號碼";
    phoneNumTextField.layer.borderWidth = 1.0f;
    self.phoneNumTextField = phoneNumTextField;
    [self.view addSubview:phoneNumTextField];
    
    UIButton *callButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [callButton setTitle:@"call" forState:UIControlStateNormal];
    [callButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    callButton.backgroundColor = [UIColor grayColor];
    callButton.center = CGPointMake(self.view.center.x, self.view.center.y+60);
    callButton.bounds = phoneNumTextField.bounds;
    [self.view addSubview:callButton];
    [callButton addTarget:self action:@selector(callButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)callButtonEvent:(UIButton *)sender {
    // 1.第一種:推薦
    NSMutableString *phoneNum = [[NSMutableString alloc] initWithFormat:@"tel:%@",self.phoneNumTextField.text];
    UIWebView *webView = [[UIWebView alloc]init];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:phoneNum]]];
    [self.view addSubview:webView];
    // 2.第二種:
//    NSString  *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",self.phoneNumTextField.text];
//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    
    
}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • 模擬器在撥打電話方法不執(zhí)行,必須真機才能撥打電話。一下方法是在iOS 8及以后系統(tǒng)下進行測試。Demo 下載 方法...
    iOS俱哥閱讀 16,709評論 5 21
  • 最近項目中需要使用到點擊號碼然后撥打電話,并且統(tǒng)計用戶是否撥打出去電話,然后發(fā)現原來的使用WebView方式無法獲...
    不知名_伍毛閱讀 2,606評論 6 11
  • iOS 10撥打系統(tǒng)電話發(fā)現彈出框會延遲2s左右出現,很不爽,研究了一下,發(fā)現是openURL在http://bl...
    Joh蝸牛閱讀 809評論 0 4
  • iOS撥打電話有三種方法。 第一種: NSMutableString *str=[[NSMutableString...
    weicyNO_1閱讀 1,750評論 0 0
  • 整理來源:iOS撥打電話(三種方法) 1、此方法,撥打完電話回不到原來的應用,會停留在通訊錄里,而且是直接撥打,不...
    huixiansheng閱讀 251評論 0 0

友情鏈接更多精彩內容