我正在从结构中获取url并将其发送到UITapGesture
,我尝试打印它(它打印url),但它不想实际打开url。
@objc func getUrl(sender: UITapGestureRecognizer){
guard let url = self.rssUrl else { return }
print(url)
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
在此处获取URL
var rssUrl: URL?
var item: RSSItem! {
DispatchQueue.global(qos: .userInteractive).async {
//other code
let store_Article = Article(dict: ["text": sum, "rssUrl": rssLink])
storedArticle.append(store_Article)
let data = dataUrl.init(articleUrl: store_Article).someUrl
DispatchQueue.main.sync {
//other code
}
}
}
编辑
它打印:http://www.instyle.com/news/rihanna-30th-birthday-party--文件:.///
举个例子
最佳答案
试试这个
编辑
@objc func getUrl(sender: UITapGestureRecognizer)
{
guard let url = URL(string: YOUR_URL_STRING) else {
return //be safe
}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
关于swift - UIApplication无法打开URL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48919543/