How to create and manage a session in iphone application?

I have an application that uses the wcf web service and after successful login, I want to activate the session for 10 minutes. If the user does not work or the application is in the background for 10 minutes, the session should expire and the application should again request login information.

I used a keychain to store the username and password and it works. But I want to add a session so that the user is redirected to the main page if the session has not expired, and to the login page if the session has expired ...

I know this is a duplicate question, but I had to write it since I am not getting the right answer from other questions. Please, help..

+6
source share
2 answers

use this link , it works for me.

use NSUserDefault to create a session for ios.

I also created a session on ios using this tutorial.

EDIT:

I have a login screen to the first page of my application

if Login was successfully authenticated by the server, I saved the username and password in NSUserDefault . In this way:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:userNameText forKey:@"username"]; [defaults setObject:passWordText forKey:@"password"]; [defaults synchronize]; 

Enable login buttons. and redirected to My Account.

In the control panel, Logout appears if the user clicks Logout Delete all data. In this way.

  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults removeObjectForKey:@"username"]; [defaults removeObjectForKey:@"password"]; [defaults synchronize]; 

& Otherwise, when the user closes the application NSUSerDefault Saved when you open the second application at that time. Verify that the username and password are stored in NSUserDefault during the ViewDidAppear Loginpage .

  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; // check if user is alraidy Login if([defaults objectForKey:@"username"]!=nil && ![[defaults objectForKey:@"username"] isEqualToString:@""]){ // Redirected to Dashboard. } 

If sucessfull then redirected to My Account.

+10
source

You can use the AFNetworking infrastructure , it automatically saves your session, I tested my APIs and worked

0
source

All Articles