当用户单击文本视图中的数字时,是否存在回调以标识用户何时单击弹出窗口中的“呼叫”?
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool
功能上面提到的会帮我找出一个链接被点击在一个UITextView,虽然是有一个特定的回调,以确定是否呼叫或点击取消点击
使用委托方法:
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
print("Phone \(URL)")
return false
}
不要忘记连接textView委托。
self.textView.delegate = self
然后,您可以添加自定义UIAlertController进行调用或取消。
编辑:
这是完整的代码:
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
if (URL.scheme == "tel"){
let phoneNumber = URL.absoluteString.stringByReplacingOccurrencesOfString("tel:", withString: "")
let alert = UIAlertController(title: phoneNumber, message: nil, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "Call", style: .Default, handler: { (alert) in
if UIApplication.sharedApplication().canOpenURL(URL) {
UIApplication.sharedApplication().openURL(URL)
}
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: { (alert) in
print("User Canceld")
}))
presentViewController(alert, animated: true, completion: nil)
return false
}
return true
}
最后一件事,在您的info.plist中添加:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
</array>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句