iOS:电话号码拨号不工作

iOS:电话号码拨号不工作,第1张

概述我正在建立一个应用程序,让您拨打荷兰的不同服务中心.问题是他们中的一些具有不同的商业格式(如0800-xxxx),设备无法拨打电话. 代码如下所示: if ([[UIApplication sharedApplication] canOpenURL:phoneURL]) { [[UIApplication sharedApplication] openURL:phoneURL];} 你有 我正在建立一个应用程序,让您拨打荷兰的不同服务中心.问题是他们中的一些具有不同的商业格式(如0800-xxxx),设备无法拨打电话.
代码如下所示:
if ([[UIApplication sharedApplication] canopenURL:phoneURL]) {    [[UIApplication sharedApplication] openURL:phoneURL];}

你有什么想法如何格式化号码或打电话,无论是格式?

编辑:这是电话号码的创建方式:

Nsstring *phoneNumberString = phoneNumber; // dynamically assignedNsstring *phoneURLString = [Nsstring stringWithFormat:@"telprompt:%@",phoneNumberString];NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
解决方法 我使用这个代码,它工作
Nsstring *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];Nsstring *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEnCoding:NSUTF8StringEnCoding];Nsstring *phoneURLString = [Nsstring stringWithFormat:@"telprompt:%@",escapedPhoneNumber];NSURL *phoneURL = [NSURL URLWithString:phoneURLString];if ([[UIApplication sharedApplication] canopenURL:phoneURL]) {    [[UIApplication sharedApplication] openURL:phoneURL];}
总结

以上是内存溢出为你收集整理的iOS:电话号码拨号不工作全部内容,希望文章能够帮你解决iOS:电话号码拨号不工作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1095974.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存