【发布时间】:2010-10-14 12:37:10
【问题描述】:
如何在 Objective-C 中拨打电话?
【问题讨论】:
-
如果您在谈论 VOIP,请尝试使用 PJSIP 库 (pjsip.org)。
标签: ios objective-c iphone
如何在 Objective-C 中拨打电话?
【问题讨论】:
标签: ios objective-c iphone
您可以拨打电话
所以这可能会起作用:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:12125551212"] options:@{} completionHandler:nil];
【讨论】:
这是从我做的一个项目中截取的:
NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",phone_number];
NSURL *phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
【讨论】:
stringWithFormat,它已经为您提供了一个自动释放的对象。
了解如何提示用户拨打号码也可能会有所帮助:
NSURL *phoneNumber = [NSURL URLWithString:@"telprompt://13232222222"];
[[UIApplication sharedApplication] openURL:phoneNumber];
telprompt 让用户可以选择在电话拨号之前拨打电话或取消拨打电话。冒号后面的两个正斜杠是可选的。
【讨论】:
tel有什么区别吗?两者似乎都提示了。
如果你说的是使用objective-c在iphone上打电话,那么你可以这样做:
NSURL *phoneNumber = [[NSURL alloc] initWithString: @"tel:867-5309"];
[[UIApplication sharedApplication] openURL: phoneNumber];
如果您正在谈论在 mac 上执行此操作,那么就像其他人提到的那样,这是基于诸如 voip、调制解调器、通过星号盒之类的东西进行连接等特定事物的数量。 .
【讨论】:
openURL 已弃用。
现在使用这个:
UIApplication *application = [UIApplication sharedApplication];
[application openURL:[NSURL URLWithString: @"tel:12125551212"] options:@{} completionHandler:nil];
【讨论】:
删除电话号码中的空格
NSString *phoneNumberString = @"123 456";
phoneNumberString = [phoneNumberString stringByReplacingOccurrencesOfString:@" " withString:@""];
phoneNumberString = [NSString stringWithFormat@"tel:%@", phoneNumberString];
NSURL *phoneNumberURL = [NSURL URLWithString:phoneNumberString]];
[[UIApplication sharedApplication] openURL:phoneNumberURL];
【讨论】:
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];
【讨论】:
这将是非常特定于平台的,或者您必须使用包装库来解释平台之间的差异,因此您最好说明它适用于哪个平台。一般来说,大多数平台上都有各种电话 API。
在 Windows 系统上,例如“TAPI”,如果您以 ISDN 等数字电话系统为目标,情况可能会有所不同,因为还有其他 API 可用。
【讨论】: