ios調打電話代碼

來源:互聯網
上載者:User

標籤:ar   io   color   os   使用   sp   for   on   bs   

// 定義點擊撥號按鈕時的操作 

- (void)callAction{ 

NSString *number = @"";// 此處讀入電話號碼

// NSString *num = [[NSString alloc] initWithFormat:@"tel://%@",number]; //number為號碼字串 如果使用這個方法 結束電話之後會進入連絡人清單

 

NSString *num = [[NSString alloc] initWithFormat:@"telprompt://%@",number]; //而這個方法則打電話前先彈框  是否打電話 然後打完電話之後回到程式中 網上說這個方法可能不合法 無法通過審核

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]]; //撥號

}

 

// 下面的代碼能在應用中添加一個電話按鈕,點擊即可撥打到電話號碼。對於 iPhone 開發人員還是很有用的。

// 添加電話表徵圖按鈕 

UIButton *btnPhone = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; 

btnPhone.frame = CGRectMake(280,10,30,30); 

[btnPhone setBackgroundColor:[UIColor redColor]];

// 點擊撥號按鈕直接撥號 

[btnPhone addTarget:self action:@selector(callAction) forControlEvents:UIControlEventTouchUpInside]; 

[self.window addSubview:btnPhone];

 

//  第三種方式打電話

 

 

 

 

 

 

-(void)CallPhone{

NSString *phoneNum = @"";// 電話號碼

NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];  

if ( !phoneCallWebView ) {          

phoneCallWebView = [[UIWebView alloc] initWithFrame:CGRectZero];// 這個webView只是一個背景容易 不需要add到頁面上來  效果跟方法二一樣 但是這個方法是合法的

[phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];

}

ios調打電話代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.