簡體   English   中英

如何在 iOS 中撥打電話?

[英]How can I make phone call in iOS?

如何在 Objective-C 中撥打電話?

您可以撥打電話

https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html

所以這可能會起作用:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:12125551212"]];

這是從我做的一個項目中剪下來的:

NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",phone_number];
NSURL *phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];

了解如何提示用戶撥打號碼也可能會有所幫助:

NSURL *phoneNumber = [NSURL URLWithString:@"telprompt://13232222222"];
[[UIApplication sharedApplication] openURL:phoneNumber];

telprompt讓用戶可以選擇在電話撥號前撥打電話或取消撥打電話。 冒號后面的兩個正斜杠是可選的。

好吧,如果您正在談論使用 objective-c 在 iphone 上撥打電話,那么您可以執行以下操作:

NSURL *phoneNumber = [[NSURL alloc] initWithString: @"tel:867-5309"];
[[UIApplication sharedApplication] openURL: phoneNumber];

如果您正在談論在 Mac 上執行此操作,那么就像其他人提到的那樣,這是基於諸如 voip、調制解調器、通過星號盒之類的東西進行連接等特定事物的數量。

刪除電話號碼中的空白

NSString *phoneNumberString = @"123 456";
phoneNumberString = [phoneNumberString stringByReplacingOccurrencesOfString:@" " withString:@""];
phoneNumberString = [NSString stringWithFormat@"tel:%@", phoneNumberString];
NSURL *phoneNumberURL = [NSURL URLWithString:phoneNumberString]];
[[UIApplication sharedApplication] openURL:phoneNumberURL];

openURL 已棄用。

現在使用這個:

UIApplication *application = [UIApplication sharedApplication];
[application openURL:[NSURL URLWithString: @"tel:12125551212"] options:@{} completionHandler:nil];
NSString *phoneNumber = @"Phone number here";
UIWebView *webView = [[UIWebView alloc] init];
NSURL *url = [NSURL URLWithString:numberString];        
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url]; 
webView.dataDetectorTypes = UIDataDetectorTypeNone;
[webView loadRequest:requestURL];

這將是非常特定於平台的,或者您必須使用包裝庫來解釋平台之間的差異,因此您最好 state 這是針對哪個平台。 通常,大多數平台上都有各種電話 API。

在 Windows 系統上,例如“TAPI”,如果您針對 ISDN 等數字電話系統,情況可能會有所不同,因為還有其他 API 可用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM