gpt4 book ai didi

swift - UIApplication 不打开 url

转载 作者:搜寻专家 更新时间:2023-11-01 05:33:23 25 4
gpt4 key购买 nike

我正在从结构中获取 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
}
}
}

编辑

it prints: http:/www.instyle.com/news/rihanna-30th-birthday-party -- file:///

举个例子

最佳答案

试试这个编辑

@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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com