문제

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 ?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top