php - Auto Login WKwebview
Get the solution ↓↓↓I have a swift 4 project and I would like to have a Auto Login feature, which means that when the users was logged in once and he restarts the app he gets automatically logged in how can I do this here is my Code: I use a WKwebview to do this i used Swift 4 if this helps. I also tryed to add a process pool as you can see in the code but it doesnt work.
import UIKit
import WebKit
class viewHome: UIViewController, WKUIDelegate, WKNavigationDelegate {
weak var navigationDelegate: WKNavigationDelegate?
static let processPool = WKProcessPool()
@IBOutlet var webViewHome: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webConfiguration.processPool = viewHome.processPool
webViewHome = WKWebView(frame: .zero, configuration: webConfiguration)
webViewHome.uiDelegate = self
webViewHome.configuration.preferences.javaScriptEnabled = true
//webViewHome.configuration.preferences.javaEnabled = true
view = webViewHome
}
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.linopura.de/jtl.php")
let request = URLRequest(url: url!)
webViewHome.configuration.preferences.javaScriptEnabled = true
//webViewHome.configuration.preferences.javaEnabled = true
webViewHome.load(request)
}
@IBAction func GoBackHome(_ sender: Any) {
if webViewHome.canGoBack {
webViewHome.goBack()
}
}
@IBAction func GoForwardHome(_ sender: Any) {
if webViewHome.canGoForward {
webViewHome.goForward()
}
}
Any ideas?
Thanks in advance
Answer
Solution:
If you are asking to keep user login persistent
In your MainVC where user lands after login try this
func saveLoggedState() {
let def = UserDefaults.standard
def.set(true, forKey: "isLoggedin")
def.synchronize()
}
call saveLoggedState() in viewdidload
In your Appdelegate
let def = UserDefaults.standard
let isLoggedin = def.bool(forKey: "isLoggedin")
if isLoggedin {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "TabbarController")
self.window?.rootViewController = initialViewController
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the metadata storage is not up to date, please run the sync-metadata-storage command to fix this issue.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.