gpt4 book ai didi

iphone - iOS:提示用户调用电话

转载 作者:行者123 更新时间:2023-12-03 19:54:41 25 4
gpt4 key购买 nike

我有一个 View ,单击时应提示用户调用电话。我正在尝试使用下面的代码:

     NSString *phoneNumber = [@"tel://" stringByAppendingString:locPhone];
NSString *phoneString = [phoneNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
phoneString= [phoneString stringByReplacingOccurrencesOfString:@"(" withString:@""];
phoneString= [phoneString stringByReplacingOccurrencesOfString:@")" withString:@""];
phoneString= [phoneString stringByReplacingOccurrencesOfString:@"-" withString:@""];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneString]];

我知道已达到代码,并且“phoneString”的最终值是一个 10 位数的电话号码。没有错误,但什么也没有发生。我错过了什么?

编辑:我现在看到 canOpenURL 返回 NO。这是因为我在模拟器上运行它吗?

最佳答案

您的代码看起来是正确的,但请注意,模拟器无法模拟电话调用(在模拟器上使用 canOpenURL 进行测试将返回 NO)。

您应该在实际设备上测试您的代码,您可能会发现它按预期工作。

顺便说一句,您确实应该在应用程序中添加 canOpenURL 测试,并在这种情况下向用户显示一些警报,因为用户可能会在 iPod 设备上运行您的应用程序,或者在iPad,都无法调用电话。

关于iphone - iOS:提示用户调用电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12786418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com