hacker
hacker

Reputation: 8947

How to check whether the user cleared the application running state in background in IPhone?

I have an iPhone application in which I am using autologin. So I am storing the credentials in local and doing the autologin.I have a logout button in the application in which I am popping back to login controller in my stack. But if the user clears the app in the background (by doubleclicking the Home button) then when he tries to logout in my app, there is no login view controller on the stack (because of autologin). Then the logout button doesn't work. Can anybody help me in tackling this situation? I am logging out like this:

   NSArray *array1 = [del.navigationController viewControllers];
   NSLog(@"%@",[del.navigationController viewControllers]);
   [del.navigationController popToViewController:[array1 objectAtIndex:0] animated:YES];

Upvotes: 0

Views: 131

Answers (1)

DivineDesert
DivineDesert

Reputation: 6954

  NSArray *array1 = [del.navigationController viewControllers];
   NSLog(@"%@",[del.navigationController viewControllers]);
   [del.navigationController popToViewController:[array1 objectAtIndex:0] animated:YES];

[array1 objectAtIndex:0] in that case wont be your login view .

So you can keep a condition like this :

  UIViewController *vw = (UIViewController *) [array1 objectAtIndex:0];
  if([vw isKindOfClass:[login class])
    [del.navigationController popToViewController:[array1 objectAtIndex:0] animated:YES];
  else
  {
   // init ur login class and push that to nav stack. 
   }

Upvotes: 1

Related Questions