objective-c - 单击电话号码字符串时调用电话

标签 objective-c ios

我有这样一个电话号码:025639879。我从数据库中以 String 的形式获取了它。 现在我想在用户单击该号码时准确调用电话,我尝试这样做:

NSString *phoneNumber=[@"tel://"stringByAppendingString:myAppGlobalVariables.telephoneTheme];


NSString *html = [NSString stringWithFormat:@"<html><body>Téléphone:%@</body
</html>",phoneNumber];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

[webView loadHTMLString:html baseURL:nil];  

我在我的应用程序中得到的是这样的:

Téléphone:tel://025639879

我错过了什么吗?提前谢谢。

最佳答案

有两种方式:

  1. 跳过 tel://并让您的 webview 将电话号码识别为链接(会有误报,所以要小心)。
  2. 制作 <a href="tel://number">number</a>链接:

    NSString *html = [NSString stringWithFormat:@"<html><body><p>Téléphone:<a href=\"tel://%@\">%@</a></p></body></html>", myAppGlobalVariables.telephoneTheme, myAppGlobalVariables.telephoneTheme]; [webView loadHTMLString:html baseURL:nil];

关于objective-c - 单击电话号码字符串时调用电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9207593/

相关文章:

ios - 错误MSB6006:“mtouch”以代码134退出。(MSB6006)

cocoa-touch - iOS - 应用内购买 & applicationDidBecomeActive

ios - 当我使用 CNContactPicker 时隐藏联系人详细信息中的操作按钮

iphone - 如何设置字体大小以填充 UILabel 高度?

objective-c - Objective C/Arduino 通信速度变慢

ios - 如何对 Cocoapods 安装进行 nuke 并从 Github master 开始

ios - 如何将字符串保存到 Core Data Swift

ios - 当格式说明符错误地传递给方法时如何发出警告

iphone - 在 objective c iPhone 中绘制标尺

ios - 让实例等待被调用的函数完成 - Swift