ios - 如何判断 Cocoa Touch 设备是否可以调用电话?

标签 ios objective-c cocoa-touch url-scheme ipod-touch

<分区>

Possible Duplicate:
iOS - Detecting whether or not device support phone calls?

我正在编写一个 iPhone 应用程序,它提供一个按钮来调用电话号码。我正在使用如下代码以通常方式使用 tel: URL 调用号码:

NSURL* contactTelURL = [NSURL
                        URLWithString:[NSString
                                       stringWithFormat:@"tel:%@",
                                       contactTel]];
[[UIApplication sharedApplication] openURL:contactTelURL];

它在真实的 iPhone 上运行良好,但我只是在模拟器中收到“不支持的 URL”警告。据推测,这也会发生在 iPod Touch 上,尽管我还没有测试过。在无法调用电话的设备上运行时,最好删除该按钮。

有没有办法以编程方式检测 Cocoa Touch 设备是否可以打电话?

最佳答案

来自诺亚·威瑟斯彭 Make a call from my iPhone application

the simulator doesn't support a lot of iOS's URL schemes, including those for the Phone, Maps, Youtube, and SMS apps. This is also the case for devices like the iPod touch and the iPad, which don't have phone capabilities; before using any URL scheme via -openURL:, you should check for support for that scheme using -canOpenURL:, which will return YES or NO depending on whether the current device supports the URL scheme you're using

所以查询 [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]] 了解设备是否可以调用电话。

关于ios - 如何判断 Cocoa Touch 设备是否可以调用电话?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/903961/

相关文章:

iOS:旋转图像,但不旋转 mask 。怎么做这个?

iphone - 仍然无法让CoreBluetooth在简单的名称发现应用程序中工作

iphone - 将 TextField 添加到 UIAlertView

ios - UIButton 垂直底部对齐不起作用

iphone - 如何让iPhone中的两个导航栏重叠?

ios - 使用 swift 启动应用程序时加载 admob 插页式广告

iphone - 查找当前时间是否在一个范围内

ios - [iOS][Objective-C] 预期类型

ios - 是否可以自定义触发 UIScrollView 滚动的滑动手势识别?

iphone - 第 5 代设备上更大的启动图像