好的,我NSDataDetector
用来检测这样的电话号码:
func matchesFor(type: NSTextCheckingResult.CheckingType) -> [String] {
do {
let nsstring = self as NSString
let detector = try NSDataDetector(types: type.rawValue)
let matches = detector.matches(in: self, options: [], range: NSRange(location: 0, length: nsstring.length))
return matches.map { nsstring.substring(with: $0.range) }
} catch {
return []
}
}
它找到一个数字。但后来我尝试像这样打开这些数字:
func makeACall(phoneNumber: String) {
if let url = URL(string: "tel://\(phoneNumber)"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.openURL(url)
}
}
它不起作用。为什么?
我的意思是:
+48 576-786-987
我应该对那个号码做任何事情来使用它来打电话吗?