【发布时间】:2017-03-19 21:19:17
【问题描述】:
UITextView 允许基于attributedText 的可点击超链接。通过实现委托方法可以拦截用户与链接的交互。 textView:shouldInteractWithURL:in: 有两种变体,适用于 iOS 10 和一种适用于 iOS 9,如下所示。
// For iOS 9 and below.
@available(iOS, deprecated=10.0)
func textView(textView: UITextView, shouldInteractWith URL: NSURL, in characterRange: NSRange) -> Bool {
// Present UIWebView here...
return false
}
@available(iOS 10.0, *)
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
// Present UIWebView here...
return false
}
在iOS 10 中运行应用程序时,iOS 10 的回调有效,但在 iOS 9 中,其他回调永远不会被调用。它直接启动 safari。
我尝试了@available 属性的各种组合,但没有任何效果。代表根本不会被调用iOS 9。
应用的Deployment Target 是iOS 9,使用Xcode 8 而Base SDK 是iOS 10.2。
更新 我正在使用 Swift 2.3
【问题讨论】:
标签: ios iphone swift xcode deprecated