Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create and manage session in iphone app?

I have an application which uses wcf web service and after successful login, i want to activate a session of 10 minutes. If user is idle or app is in background for 10 minutes then session should expire and app should ask for login details again.

I have used keychain for storing username and password and it works But i want to add the session so that user is redirected to main page if session is not expired and to the login page if session is expired...

I know this is repeated question but i had to write it since i am not getting proper answer from other questions. Please help..

like image 885
Shaunak Avatar asked Feb 05 '13 08:02

Shaunak


People also ask

What is IOS session?

Sessions track a common pattern, in which a given user opens an app and interacts with it for a period of time, then moves on to another app, or stops using their device. Various Output partners use sessions to group user interactions. All events tracked during a session will also share a Session ID.

What is session in mobile app?

A session is a period of time wherein a user interacts with an app. Usually triggered by the opening of an app, a session records the length and frequency of app use to show developers, marketers and product managers how much time users spend within an app.

How do you end a session on iPhone?

To exit a session on an iPhone, tap the Actions button, and then tap the End or Hold Session button at the bottom of the menu. If you are the session owner, End Session closes the session page in your representative console and removes any additional representatives who may be sharing the session.


1 Answers

use this Link this works me.

use NSUserDefault to create Session for ios.

i also created Session in ios with this Tutorial.

EDIT:

i have a Login Screen in first Page of My application

if Login is Successfull authenticate by server then i stored my Username & Password in NSUserDefault Like this way:

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

Onclick of Login Button. & redirected to Dashboard.

In dashboard Logout Button is there if user click Logout Delete All Data Like this way.

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

& On other condition when user close app The NSUSerDefault Are stored when u second time open app at that time Check wheather username & password stored in NSUserDefault During ViewDidAppear of 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 Dashboard.

like image 193
Dixit Patel Avatar answered Oct 19 '22 11:10

Dixit Patel