iOS:电话号码拨号不工作

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

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

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

Nsstring *phoneNumberString = phoneNumber; // dynamically assigned
Nsstring *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 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...