【发布时间】:2013-04-03 15:06:35
【问题描述】:
在IOS中,如何删除+-#*(),从通讯录中获取。 例如:
NSString *txt = @"+1(510)1234567"
txt = [NSString stringWithFormat:@"tel://%@", txt];
[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:txt]];
这是一个无效的号码。
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlToCall]]; 对这个类型号没用。
我可以有一些更好的选择,除了使用
[txt stringByReplacingOccurrencesOfString:@"-" withString:@""]....
我只是想打个电话。
感谢您的帮助。
其实:我们可以通过openURL进行通话:通话的格式不是“tel://”,而是“tel:”。 所以,我应该做的是:
NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:
[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"]
invertedSet]] componentsJoinedByString:@""];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", cleanedString]];
没关系。
————————————————————————————————— @"tel://" 不是拨打电话的正确网址! 我们必须使用@"tel:"
如果不是某个数字,例如 +1 (510) 3436
BOOL bCanCall = [[UIApplication sharedApplication]canOpenURL:urlToCall];将返回 False。你不能打电话。
【问题讨论】:
-
正则表达式或 removeCharacterInSet 等
-
谢谢。它成功了。顺便说一句,判断号码是否对通话有用的正确方法?
-
什么是有用的数字?银行/女朋友的朋友等的数量?你需要检查。如果您要求提供有效号码,您可以检查。
-
tel:URL 具有a specification。也就是说,它不排除 URL 中的特殊字符,因此 iOS 似乎偏离了它。
标签: iphone ios phone-number openurl