I'm making a social iOS app. In order to "remember" user's login status, what I did so far:
for the first time the user logs in/create a new account, the app saves his/her username and password in keychain, and next time when the app launches, in
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// submit login
}
the app submits the username/password in keychain to login the user automatically;
Now suppose after the app launches and automatic login happens, if the app entered background for a long time(longer than 2 hours) and then switch back to foreground, is the user NO LONGER logged in?
If the login status is gone, how can I remain the login status? What I can think of is to add another automatic login logic in
- (void)applicationWillEnterForeground:(UIApplication *)application {
// submit login
}
But wouldn't that be too much data transmission involved?
Or maybe I can set a permanent session time on the server side? Is that even possible?
Best way to achieve this functionality is to generate a token key for mobile device which can be expire in a long time, you can keep it alive like for 30 days and only invalidate until user logout manually.