title: iOS 6 - State Preservation and Restoration
body: <p>I have implemented iOS 6 API for state saving, it works - after I quit the app and launch back in for some milliseconds the restored view controller fly in, but then it's replaced by the main view controller I display at launch.</p>
  
  <p>I'm setting every time the app launch the root view of the main window, so this must be the issue.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
      [self commonInitializationLaunching:launchOptions];
      return YES;
  }
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
      [self commonInitializationLaunching:launchOptions];
      return YES;
  }
  
  - (void)commonInitializationLaunching:(NSDictionary *)launchOptions
  {
      static dispatch_once_t onceToken;
      dispatch_once(&amp;onceToken, ^{
  
          self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
          // Override point for customization after application launch.
          static NSString *const kKeychainItemName = @"OAuthGoogleReader";
          self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
          self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
  
          GTMOAuth2Authentication *auth;
          auth = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
                                                                       clientID:kClientID
                                                                   clientSecret:kClientSecret];
  
          self.window.rootViewController = self.navController;
  
          [self.window makeKeyAndVisible];
  
          BOOL isSignedIn = [auth canAuthorize];
          if (isSignedIn) {
              NSLog(@"Signed");
          }else{
              NSString *scope = @"https://www.google.com/reader/api/";
  
              GTMOAuth2ViewControllerTouch *viewController;
              viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:scope
                                                                          clientID:kClientID
                                                                      clientSecret:kClientSecret
                                                                  keychainItemName:kKeychainItemName
                                                                          delegate:self
                                                                  finishedSelector:@selector(viewController:finishedWithAuth:error:)];
              [self.navController pushViewController:viewController animated:YES];
              //        self.window.rootViewController = viewController;
          }
      });
  }
  </code></pre>
  
  <p>You can see that in -(void)commonInitializationLaunching:(NSDictionary *)launchOptions
  I'm setting my window's root view. I don't know what to put in there. Perhaps check if there is saved state and then load this method? But how?</p>
  
  <p>Thanks!</p>
  
  <p>Here is what I've tried following Rob's advice:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
      if (!self.isRestored) {
          self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
      }
      [self commonInitializationLaunching:launchOptions];
      [self.window makeKeyAndVisible];
      return YES;
  }
  </code></pre>
  
  <p>with nothing in <code>willFinishLaunching</code>...
  I also removed by window code from my <code>commonInitializationLaunching</code> method.</p>