![]() ![]() ![]() ![]() |
|||||
|
|||||
樓主 林耿立 ![]()
![]() |
大家好,我是IOS初學者,近期遇到一個問題 關於wkwebview作facebook留言外掛程式 點選登入即可留言時,都無反應,登入後也無法留言的情況 在UIwebview時顯示都沒問題,但這個要被destroy了 所以想問各位大大,是否跟cors有關,此題有解嗎?? import UIKit import WebKit import FBSDKCoreKit class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate { lazy var testWebView: WKWebView = { [unowned self] in let wkWebView = WKWebView(frame: self.view.frame) wkWebView.uiDelegate = self wkWebView.navigationDelegate = self wkWebView.configuration.preferences.javaScriptEnabled = true wkWebView.configuration.preferences.javaScriptCanOpenWindowsAutomatically = true wkWebView.configuration.suppressesIncrementalRendering = true return wkWebView }() override func viewDidLoad() { super.viewDidLoad() setupView() loadWebUrl() } func setupView() { view.addSubview(testWebView) } func loadWebUrl() { let url = URL(string: "XXXX") testWebView.load(request) testWebView.loadHTMLString("<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=v8.0&appId=XXXX&autoLogAppEvents=1';fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script><div class='fb-comments' data-href='XXXX' data-numposts='5'></div></body></html>", baseURL: url) } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Add FBSDK fix ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions); return true } func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { // Add FBSDK fix return ApplicationDelegate.shared.application(app, open: url, options: options) //return CAPBridge.handleOpenUrl(url, options) } func webView(webView: WKWebView, createWebViewWithConfiguration configuration: WKWebViewConfiguration, forNavigationAction navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? { // A nil targetFrame means a new window (from Apple's doc) if (navigationAction.targetFrame == nil) { // Let's create a new webview on the fly with the provided configuration, // set us as the UI delegate and return the handle to the parent webview let popup = WKWebView(frame: self.view.frame, configuration: configuration) popup.uiDelegate = self self.view.addSubview(popup) return popup } return nil; } func webViewDidClose(webView: WKWebView) { // Popup window is closed, we remove it webView.removeFromSuperview() } } |