UIActivityViewController 不适用于 WKWebView
Posted
技术标签:
【中文标题】UIActivityViewController 不适用于 WKWebView【英文标题】:UIActivityViewController not working with WKWebView 【发布时间】:2020-04-17 10:12:40 【问题描述】:如何在swift中实现WKWebView的UIActivityViewController?
我有以下 UIActivityViewController 实现,不幸的是,共享操作的 ActivityView 没有显示。
代码更新:
class ViewController: UIViewController, WKNavigationDelegate
var webView: WKWebView!
override func viewDidLoad()
super.viewDidLoad()
self.loadView();
override func loadView()
webView = WKWebView()
webView.navigationDelegate = self
view = webView
let url = URL(string: "https://www.google.com")!
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
webView.allowsLinkPreview = true
let items = [url]
let activityViewController = UIActivityViewController(activityItems: items , applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
self.present(activityViewController, animated: true, completion: nil)
...
【问题讨论】:
请问,你的位置在哪里? @IMHiteshSurani 我在我的问题中添加了代码更新 您只需要在 viewDidAppper 中添加共享代码,而不是 viewDidLoad 方法。我稍后会添加详细代码 【参考方案1】:你不能present
viewDidLoad
中的控制器
代码:
var webView: WKWebView!
override func viewDidLoad()
super.viewDidLoad()
loadCMSData()
fileprivate func loadCMSData()
webView = WKWebView()
webView.navigationDelegate = self
view = webView
let url = URL(string: "https://www.google.com")!
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
webView.allowsLinkPreview = true
override func viewDidAppear(_ animated: Bool)
let url = URL(string: "https://www.google.com")!
let items = [url]
let activityViewController = UIActivityViewController(activityItems: items , applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
self.present(activityViewController, animated: true, completion: nil)
【讨论】:
以上是关于UIActivityViewController 不适用于 WKWebView的主要内容,如果未能解决你的问题,请参考以下文章
UIActivityViewController 共享 UIActivity 未显示
UIActivityViewController 不适用于 WKWebView
限制 UIActivityViewController 共享扩展活动