Skip to content

Commit

Permalink
Merge pull request pichillilorenzo#7 from jj-lin/TWECACAPP-560-Facebo…
Browse files Browse the repository at this point in the history
…ok-login-at-merchant-page

Handle Facebook Login at merchant page
  • Loading branch information
eJamesLin authored and GitHub Enterprise committed Jun 9, 2020
2 parents 598402b + 45801c2 commit add05c6
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions ios/Classes/InAppWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,11 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
}

public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
if (popupWebView != nil) {
popupWebView?.removeFromSuperview()
popupWebView = nil
}

currentURL = url
InAppWebView.credentialsProposed = []
evaluateJavaScript(platformReadyJS, completionHandler: nil)
Expand Down Expand Up @@ -2060,15 +2065,40 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
lastScrollX = scrollView.contentOffset.x
lastScrollY = scrollView.contentOffset.y
}


var popupWebView : WKWebView?

// sample url: https://m.facebook.com/v2.8/dialog/oauth?app_id=1091264071008011....
func isFacebookLogin(url: URL) -> Bool {
return url.host?.contains("facebook") == true && url.path.contains("oauth")
}

public func webView(_ webView: WKWebView,
createWebViewWith configuration: WKWebViewConfiguration,
for navigationAction: WKNavigationAction,
windowFeatures: WKWindowFeatures) -> WKWebView? {
onCreateWindow(url: navigationAction.request.url!, navigationType: navigationAction.navigationType)
guard let url = navigationAction.request.url else { return nil }

if navigationAction.targetFrame?.isMainFrame != true && isFacebookLogin(url: url) {
let newWebView = WKWebView(frame: webView.frame, configuration: configuration)
newWebView.load(navigationAction.request)
newWebView.uiDelegate = self
webView.superview?.addSubview(newWebView)
popupWebView = newWebView
return newWebView
}

onCreateWindow(url: url, navigationType: navigationAction.navigationType)
return nil
}


public func webViewDidClose(_ webView: WKWebView) {
webView.removeFromSuperview()
if webView === popupWebView {
popupWebView = nil
}
}

public func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {
onWebContentProcessDidTerminate()
}
Expand Down

0 comments on commit add05c6

Please sign in to comment.