Iphone session management

How can I manage user sessions in the iPhone app? I get the username and password from the user on the first page of my application. User can log out whenever he wants. How to store session information in the iPhone application, like any other web application? Is there any other technique for this? thanks.

+2
source share
2 answers

You can call NSUserDefaults from anywhere in your application. Usually this status information is saved.

If you assume that you may need to store information for a large number of users, you should create a user database and only rely on it. The easiest way to do this is to use Master Data . You can park the context of the managed entity in the applicationโ€™s deletion, and then access it from anywhere by calling the application delegate.

I would warn you that the iPhone application has a different design template than the web application. You should not think about pages and sessions unless you use the web interface.

+2
source

you can save user information in NSUserDefaults

 -(void)saveToUserDefaults:(NSString*)myString { NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; if (standardUserDefaults) { [standardUserDefaults setObject:myString forKey:@"username"]; [standardUserDefaults synchronize]; } } 

if you have user information in NSUserDefaults, you can get information about your username

 -(NSString*)retrieveFromUserDefaults { NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; NSString *val = nil; if (standardUserDefaults) val = [standardUserDefaults objectForKey:@"username"]; return val; } 

with the help of :

 NSString * username=[self retrieveFromUserDefaults:@"username"]; if (!([username length]==0)||![username isEqualToString:@""]) { NSLog(@"no authentication and redirect authentication page "); } else { NSLog(@"it authentication!"); } 
0
source

All Articles