Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8653939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:39:46+00:00 2026-06-12T14:39:46+00:00

I have implemented iOS 6 API for state saving, it works – after I

  • 0

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.

I’m setting every time the app launch the root view of the main window, so this must be the issue.

Here is my 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(&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;
        }
    });
}

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?

Thanks!

Here is what I’ve tried following Rob’s advice:

- (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;
}

with nothing in willFinishLaunching…
I also removed by window code from my commonInitializationLaunching method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:39:48+00:00Added an answer on June 12, 2026 at 2:39 pm

    Storyboards will do most of the heavy lifting for you, such as restoring the window. Using code, however, will not restore the window. You will need to hold on to your root view controller using the encoder. Your code will look something like this:

    NSString * const AppDelegateRootVCKey = @"AppDelegateRootVCKey";
    
    - (void)application:(UIApplication *)application willEncodeRestorableStateWithCoder:(NSCoder *)coder {
        [coder encodeObject:self.window.rootViewController forKey:AppDelegateRootVCKey];
    }
    
    - (void)application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder {
    
        // Grabs the preserved root view controller.
        UIViewController * vc = [coder decodeObjectForKey:AppDelegateRootVCKey];
    
        if (vc) {
            UIWindow * window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
            window.rootViewController = vc;
            window.restorationIdentifier = NSStringFromClass([window class]);
    
            // The green color is just to make it obvious if our view didn't load properly.
            // It can be removed when you are finished debugging.
            window.backgroundColor = [UIColor greenColor];
    
            self.window = window;
        }
    }
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        if (!self.window) {
    
            UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
            // The blue color is just to make it obvious if our view didn't load properly.
            // It can be removed when you are finished debugging.
            window.backgroundColor = [UIColor blueColor];
    
            UIViewController *root = // However you create your root.
    
            window.rootViewController = root;
            window.restorationIdentifier = NSStringFromClass([window class]);
    
            self.window = window;
        }
    
        [self commonInitializationLaunching:launchOptions];
        [self.window makeKeyAndVisible];
    
        return YES;
    }
    

    Another gotcha to watch out for is to make sure that your UINavigationControllers and UITabBarControllers have restoration identifiers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented Single-Sign-On in my iOS 4.3 app successfully. Now I want to
I have implemented Google Analytics tracking in my iOS app and it is working,
I have implemented xmpp chat in ios app, connection get established, get authenticated, message
I have an iOS app which gets some JSON from a server (in the
I have integrated the iOs Facebook API into my app successfully. Now, I want
I started to use IOS and the Graph Api some weeks ago. I have
I have implemented a CorePlot graph in my iOS application, however I am unable
i have implemented code like here but it's not working for iOS 5.0, it
I've integrated the Facebook sso for iOS and have the single sign on implemented
I have implemented correctly bump's api, and added this code: - (void) configureBump {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.