简体   繁体   中英

Managing iOS app UI state based on user being logged in or not

I have an app which presents a login screen on first launch. When the user logs in, I give them an option to remain logged in. This establishes a session with an expiry on my server. What's the most appropriate way to do the following things:

  1. Store whether the user is logged in or not.
  2. Present the user with a login or logout option on application launch based on the validity of their session.
  3. End their current session if they choose to logout (or if their session is expired).

I'm guessing this is a common design pattern and there should be tried and tested ways to do this but I seem to be using the wrong terms to search because I haven't found a satisfactory answer.

Some ideas:

  1. I would suggest you store your sensitive session information in the application's KeyChain. I wouldn't store here the state of wether the user is logged in or not, just store that in memory. Your webservice should be able to return an error when the session ceases to exist, or if the user has logged out.
  2. If the backend determines the session's validity, then you should have a RESTful call where you can pass the session information, returning whether the session is still valid.
  3. Again, if they choose to logout, then you could perform another call to your backend passing the session information.

For the Keychain, use the KeychainItemWrapper from Apple's examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM