在WKWebView中实现Facebook评论插件

时间:2018-08-10 06:19:09

标签: ios swift html5 webview wkwebview

我尝试在我的webView中实现facebook comment plugin

但是在webView上我什么也没得到

我的代码:

class ViewController: UIViewController {

var webView: WKWebView!
let htmlString = "<html><head> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> </head><body><div id=\"fb-root\"></div><script>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s); js.id = id;js.src = 'https://connect.facebook.net/zh_TW/sdk.js#xfbml=1&version=v3.1&appId=1924954050908325&autoLogAppEvents=1';fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script><div class=\"fb-comments\" data-href=\"https://example.com\" data-numposts=\"5\"></div></body></html>"

override func viewDidLoad(){
    super.viewDidLoad()
    webView = WKWebView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
    webView.scrollView.bounces = false
    self.view.addSubview(webView)
    webView.loadHTMLString(htmlString, baseURL: URL(string: "https://example.com"))
}
}

有时可行

ScreenShot

0 个答案:

没有答案
相关问题