Managing iOS app UI state based on user login or not

I have an application that is a login screen on first launch. When a user logs in, I give them the option to stay logged in. This sets up an expiring session on my server. What's the most appropriate way to do the following:

  • Save whether the user is registered or not.
  • Give the user the option to log in or log out when the application starts, depending on the validity of their session.
  • End their current session if they want to log out (or if their session has expired).

I am guessing this is a general design pattern and there should be a lot of testing and validation for ways to do this, but I seem to be using the wrong search terms because I haven't found a satisfactory answer.

+3


source to share


1 answer


Some ideas:

  • I suggest you keep your session confidential in the KeyChain app. I won't be storing the state here whether the user is logged in or not, just store it in memory. Your web service should be able to return an error when the session ceases to exist, or if the user is logged out.
  • If the backend determines the expiration of the session, then you should have a RESTful call in which you can pass in information about the session, returning whether the session is actually valid.
  • Again, if they choose to log out, you can make another call to their backend passing in the session information.


For keychain use KeychainItemWrapper from Apple examples.

+1


source







All Articles