美文网首页Swift
swift动态获取WKWebView title

swift动态获取WKWebView title

作者: zanyzephyr | 来源:发表于2018-08-15 10:38 被阅读47次
    webView.uiDelegate = self
    webView.addObserver(self, forKeyPath: "title", options: NSKeyValueObservingOptions.new, context: nil)
    

    然后在回调方法中

        override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?){
            if keyPath == "title" {
                if object as? WKWebView == webView {
                    title = webView.title ?? ""
                }
            }
        }
    

    相关文章

      网友评论

        本文标题:swift动态获取WKWebView title

        本文链接:https://www.haomeiwen.com/subject/upmibftx.html