好開,我用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不接受空間:)什麼是顯而易見的:) –
不客氣! :) –