好开,我用NSDataDetector
来检测这样的电话号码:电话号码无法使用的OpenURL
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
我应该做任何与该号码以呼叫使用它?
谢谢,它的工作原理...它看起来像url不接受空间:)什么是显而易见的:) –
不客气! :) –