mardi 21 juillet 2020

Swift how to safe user login session with checkbox "Remember Me"

i have a question about my app that i develop, in my login screen i have this checkbox when the user check that box, his username(or in my case his phone number to login) will automatically safe in the textfield where if the user logout, his phone number will automatically fill in the textfield.

Where if the user not check that box, his phone number will not gonna safe in the user session so when the user logout, his phone number will not fill the login textfield.

that checkBox is for "remember me", when user check that box it will remember the user phone number and if not check the box it will not remember the user phone for the next time the user login.

any idea how guys?

Image

heres my code :

@IBAction func toggleCheckBox(_ sender: UIButton) {
    
    if sender.isSelected == true {
        checkBoxBtn.setImage(UIImage(named: "Checked-1"), for: .normal)
        sender.isSelected = false
    }else{
        checkBoxBtn.setImage(UIImage(named: "unCheck"), for: .normal)
        sender.isSelected = true
    }
    
}


//this code is for user session
if FIRST_BOOT {
        print("first boot")
        if let save_session = UserDefaults.standard.string(forKey: "USER_FULLNAME") {
            USER_FULLNAME = save_session
        }
        if let save_session = UserDefaults.standard.string(forKey: "SESSION_TOKEN") {
            SESSION_TOKEN = save_session
        }
        if let save_session = UserDefaults.standard.string(forKey: "USER_PIN") {
            USER_PIN = save_session
        }
        if let save_session = UserDefaults.standard.string(forKey: "USER_TELEPHONE") {
            USER_TELEPHONE = save_session
        }
       
        if let save_session = UserDefaults.standard.string(forKey: "IDENTITY_NUMBER") {
            IDENTITY_NUMBER = save_session
        }
        
        if let _ = UserDefaults.standard.string(forKey: "WIZARD") {
            // Wizard has opened
        } else {
            //performSegue(withIdentifier: "loginToWizard", sender: nil)
            
            //return
        }



  //i use that code to put the user phone num into the textfield
if let save_session = UserDefaults.standard.string(forKey: "USER_TELEPHONE_CACHED") {
        textPhoneNumber.text = save_session.substring(from: 1)
    }
  
  

can anyone tell me how to do the thing that i want? i want just to put that user session inside the checkbox func but i just see alot of bugs after that, im asking about the steps on how to do it, cause im kinda confused how even though its seems not so difficult.... thanks guys.




Aucun commentaire:

Enregistrer un commentaire