从我的 iPhone 应用程序拨打电话

发布于 2024-09-10 23:15:23 字数 667 浏览 6 评论 0原文

我已经实现了通过单击酒店的一排描述性表格视图来拨打电话的功能;我通过在方法“didSelectRowAtIndexPath”中编写以下代码来使用 URL 方案:

NSString *phoneNumber=element.phone;                                       
[NSString *phoneNumberScheme = [NSString stringWithFormat:@"tel:%@ ", phoneNumber];
NSlog(phoneNumberScheme);                      
phoneNumberScheme = [phoneNumberScheme stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumberScheme]];

没有错误!通过 NSlog,我验证了该数字是否正确读取,确实如此(实际上控制台上显示电话:1-408-555-5555)。问题是什么也没发生!!!

此时(也基于我在网上读到的内容)我怀疑我无法在模拟器上测试这个东西!我做错了什么或者我不能在模拟器上测试这个“URL 方案”吗?!

I have implemented the ability to make a call from clicking on a row of descriptive tableview of my hotel; I used the URL scheme by writing the following code in method "didSelectRowAtIndexPath ":

NSString *phoneNumber=element.phone;                                       
[NSString *phoneNumberScheme = [NSString stringWithFormat:@"tel:%@ ", phoneNumber];
NSlog(phoneNumberScheme);                      
phoneNumberScheme = [phoneNumberScheme stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumberScheme]];

No error! With NSlog I verified that the number was read correctly, and so it is (indeed on console appears tel:1-408-555-5555). The problem is that nothing happens!!!

At this point (also based on something I read on the web) I have a doubt that I can't test this thing on simulator! Am I doing something wrong or can't I test this "URL scheme" on the simulator?!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月光色 2024-09-17 23:15:23

扩展 seanny94 的答案:模拟器不支持很多 iOS 的 URL 方案,包括电话、地图、Youtube 和 SMS 应用程序的 URL 方案。 iPod touch 和 iPad 等不具备电话功能的设备也是如此。在通过 -openURL: 使用任何 URL 方案之前,您应该使用 -canOpenURL: 检查对该方案的支持,这将返回 YES 或 < code>NO 取决于当前设备是否支持您正在使用的 URL 方案。

To expand on seanny94's answer: 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.

懷念過去 2024-09-17 23:15:23

您无法在模拟器中测试电话呼叫(或任何基于电话的功能)。没有人支持它。

You can't test a phone call (or any phone-based function, for that matter) in the Simulator. There is no support for it.

病女 2024-09-17 23:15:23

尝试这个有用的代码

删除代码中的空格

NSString *trimmedString = [yourNumberString stringByReplacingOccurrencesOfString:@" " withString:@""];

确认后拨打电话的

NSString *phoneNumber = [@"telprompt://" stringByAppendingString:trimmedString];

代码 直接呼叫的代码

NSString *phoneNumber = [@"tel://" stringByAppendingString:trimmedString];
NSLog(@"Number : %@",phoneNumber);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

Try this useful code

Remove spaces for your code

NSString *trimmedString = [yourNumberString stringByReplacingOccurrencesOfString:@" " withString:@""];

Code for Call after confirmation

NSString *phoneNumber = [@"telprompt://" stringByAppendingString:trimmedString];

Code for direct calling

NSString *phoneNumber = [@"tel://" stringByAppendingString:trimmedString];
NSLog(@"Number : %@",phoneNumber);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文