iOS SDK stayLoggedIn

Hi.

I would like to use the stayLoggedIn functionality in iOS SDK, but i don´t understand well how it really works. Besides setting stayLoggedIn to YES, how can i check the logged in user when the app restarts and reload its data?

Regards,
Andrés

Hi Andrés,

If after app restarts currentUser != nil, then the login information from the previous run had been restored.

We also added a method to validate stored login to make sure it is still active, and that build will be published on the download section of the site soon.

Regards,
Mark

Thanks Mark.

It works but i have a doubt. What would happen with this if user logs in in another device? In my app i have the “Enable Multiple Logins” and “Enable Session Timeout” to OFF, so i understand that the new session will invalidate the older one. My doubt is if the user starts again the app in the first device he was using, how can i know that session is invalid and force the user to log in again?

Is there a way to know a user token is currently valid?

Regards,
Andrés

Hi.

Could you check this?

Regards,
Andrés

Hi, Andres.

“Is there a way to know a user token is currently valid?”

In backendless.userService was added isValidUserToken method.
It checks user token(is it valid or not) and returns true or false.
You should download last IOS SDK.

Regards,
Kate.

Hi Kate.

Thanks, i will try it. Is there something similar in Android SDK?

Regards,
Andrés

You can check the state of isStayLoggedIn property and is user token valid or not, for example, in AppDelegate.m file:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[backendless initApp:APP_ID secret:SECRET_KEY version:VERSION_NUM];
if (backendless.userService.isStayLoggedIn) {


NSNumber *result = [ backendless.userService isValidUserToken ];
NSLog(@"isValidUserToken: %@", [ result boolValue ] ?@"YES" : @"NO");
[ backendless.userService setStayLoggedIn: [result boolValue] ];
}
return YES;
}

Please note that the data from the StayLoggedIn mode is saved locally (as cookies) - you can not use the same user token on different devices.