Question

I want to maintain the session in my iphone application. If the application Enters in to Background state or goes inactive So I have to keep same screen which I closed last. How to do this one?

For Instance, In my app, User have to register only once.. If user successfully registered then user will be moved to next screen so when the user opens the app next time the same screen would be shown. I know that It can be done through NSUserDefaults but how to do in my case ?

Était-ce utile?

La solution

set the value For which page you want to set the session

For example I want to save the session for register.m page

NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]
defaults setObject:@"1" forKey:@"Register"];
[defaults synchronize];

in my app i have used main.m as firstpage so in viewDidLoad of same page to get value

- (void)viewDidLoad
{
   self.navigationController.navigationBar.hidden=YES;
   [super viewDidLoad];
   NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
   NSString* strValue =   [defaults objectForKey:@"Register"];

    NSLog(@"NSUserDefaults.....>%@",strValue);

    if ([strValue isEqualToString:@"1"])
    {
        VerificationViewController *rf = [[VerificationViewController alloc] initWithNibName:@"VerificationViewController" bundle:nil];
        [self.navigationController pushViewController:rf animated:YES];
    }
}

navigate the page in if condition on which you want to navigate the control when next time the application open by the user

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top