
代码如下所示:
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:电话号码拨号不工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)