Autofill username into web view
When the user firsts signs in you need to listen to
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool
Here you can get the post data, which should contain the username, password, and remember username values. Check if the remember username is checked and then save the username to core data.
When the user logs in any other time, use this webViewDidFinishLoad(_ webView: UIWebView)
to fill in the username text field.
You can do this by using the webView.stringByEvaluatingJavaScript(from: String)
You'll need to use some javascript and it should be something like this.
document.getElementByID('id of the username text field').value = username
So for your website, your delegate methods should look like this.
func webViewDidFinishLoad(_ webView: UIWebView) {
if let url = webView.request?.url {
if url.absoluteString == "https://retail.onlinesbi.com/retail/login.htm" {
// Autofill the username and password here.
webView.stringByEvaluatingJavaScript(from: "document.getElementById('username').value = \"username\"")
webView.stringByEvaluatingJavaScript(from: "document.getElementById('label2').value = \"password\"")
}
}
}
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if let url = webView.request?.url {
if url.absoluteString == "https://retail.onlinesbi.com/retail/login.htm" {
// Get the username and password here.
let username = webView.stringByEvaluatingJavaScript(from: "document.getElementById('username').value")
let password = webView.stringByEvaluatingJavaScript(from: "document.getElementById('label2').value")
}
}
return true
}
How to use autoFill with keychain access in WKWebView
Almost sure this has been answered elsewhere, but Enabling Password AutoFill on an HTML Input Element from Apple's docs is what you need.
TL;DR:
<input id="user-text-field" type="email" autocomplete="username"/>
<input id="password-text-field" type="password" autocomplete="current-password"/>
Related Topics
Uitextview Change Text Color of Specific Text
Map and Flatmap Difference in Optional Unwrapping in Swift 1.2
Add Constraints to Generic Parameters in Extension
Get Signed Integer from Swift String of Binary
How to Cast an Any Value with Nil in It to a Any
Perform Segue from Another Class with Helper Function
How to Change Navigationbar Font in Swift
How to Save Document to "Files" App in Swift
Why Does Adding 'Dynamic' Fix My Bad Access Issues
Fatal Error: Array Index Out of Range in Swift Xcode6
How to Implement iOS 11's Mkusertrackingbutton
If the Swift 'Guard' Statement Must Exit Scope, What Is the Definition of Scope
Multi-Face Detection in Realitykit
What's the Best Way to Iterate Over Results from an API, and Know When It's Finished
Callkit - How to Bring the Cxcallcontroller to the Front
Libsqlite3.Dylib and Libz.Dylib Missing in Xcode 7. How to Use Parse