We are developing an application for iOS 8.0 and above. This application requires authentication (or that the user registers for it). On the website, we use html forms to register and login users. These forms are responsive. User can also click on the "Log me in with Facebook button" to log in with FB credentials. This button is implemented with FB's SDK for Javascript (v2.4)
As such, we do not want to implement native screen on our iOS application for registration and log, but we rather implemented a view controller with a WKWebView
element to handle this browsing experience.
However, we have noted that, when users tap on the "Log me in with Facebook button", nothing happens. The typical pop-up that FB opens to ask a user for login and grant permissions never appears.
Here is how we are initializing the WKWebView
:
class LoginViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {
var webView: WKWebView
@IBOutlet weak var cancelButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(webView)
webView.setTranslatesAutoresizingMaskIntoConstraints(false)
let height = NSLayoutConstraint(item: webView, attribute: .Height, relatedBy: .Equal, toItem: view, attribute: .Height, multiplier: 1, constant: 0)
let width = NSLayoutConstraint(item: webView, attribute: .Width, relatedBy: .Equal, toItem: view, attribute: .Width, multiplier: 1, constant: 0)
view.addConstraints([height, width])
loadDefaultUrl()
}
required init(coder aDecoder: NSCoder){
let config = WKWebViewConfiguration()
config.preferences.javaScriptCanOpenWindowsAutomatically = true
self.webView = WKWebView(frame: CGRectZero, configuration: config)
super.init(coder: aDecoder)
webView.navigationDelegate = self
webView.UIDelegate = self
}
Would appreciate any pointers on how to make the FB login button work within a WKWebView
(or, if doable, within a UIWebView
).