Simulator vs device


#1

I have a iPHone 5 running 7.1. I get this error when I run on the device via the debug area, but not while on the simulator:

Warning: Unable to create restoration in progress marker file

any ideas?

It works, but for the error message.


#2

This warning shows up when the app launches at the very first time with restoration set. It happens on both simulator and device. You can check by clean start; removing the app and then starting. So, I guess it’s just due to no restoration info at the very first time.


#3

I’m getting the same error. Both the simulator and my device get a black screen with the same message. I’ve tried removing the app and re-running Xcode, but nothing changes. I’ve also gone over the code 3 times and can’t find any mistakes… Any advice?

Is there something wrong in the method below? I get “No windows have a root view controller, cannot save application state” in the console when I exit the app on my device/simulator.

[code]@implementation BNRAppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    if (!self.window.rootViewController) {
    BNRItemsViewController *itemsViewController = [[BNRItemsViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:itemsViewController];

      navController.restorationIdentifier = NSStringFromClass([navController class]);
      self.window.rootViewController = navController;
    

    }
    [self.window makeKeyAndVisible];
    return YES;
    }[/code]


#4

Make sure you’ve also implemented the following method, as given by the book:

[code]- (UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
{
// Create a new navigation controller
UIViewController *vc = [[UINavigationController alloc] init];

// The last object in the path array is the restoration
// identifier for this view controller
vc.restorationIdentifier = [identifierComponents lastObject];

// If there is only 1 identifier component, then
// this is the root view controller
if ([identifierComponents count] == 1) {
    self.window.rootViewController = vc;
}

return vc;

}[/code]


#5

I did implement the method. These are the logs I get in the console:

When I run the app:
2014-05-14 16:12:01.201 Homepwner[3083:60b] Warning: Unable to create restoration in progress marker file

When I exit the app (home button):
2014-05-14 16:12:27.384 Homepwner[3083:60b] Saved all of the BNRItems
2014-05-14 16:12:27.385 Homepwner[3083:60b] No windows have a root view controller, cannot save application state


#6

It so happens I still have an iPhone 5 with iOS7.1 on it. I ran it on the device, and as indicated by sunn4s, the first line message appeared. When I ran it for the second time, I had no error messages and it ran properly. I tested the state restoration and it did as predicted.

There’s most likely something in your code that’s causing it. Post yourentire AppDelegate.m file (for starters) to give a clue.


#7

Here it is:

#import "BNRAppDelegate.h"
#import "BNRItemsViewController.h"
#import "BNRItemStore.h"

@implementation BNRAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if (!self.window.rootViewController) {
        BNRItemsViewController *itemsViewController = [[BNRItemsViewController alloc] init];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:itemsViewController];
        
        navController.restorationIdentifier = NSStringFromClass([navController class]);
        self.window.rootViewController = navController;
    }
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    BOOL success = [[BNRItemStore sharedStore] saveChanges];
    if (success) {
        NSLog(@"Saved all of the BNRItems");
    } else {
        NSLog(@"Could not save any of the BNRItems");
    }
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

-(BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder
{
    return YES;
}

-(BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder
{
    return YES;
}

-(UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
{
    // Create a new navigation controller
    UIViewController *vc = [[UINavigationController alloc] init];
    
    // The last object in the path array is the restorarion view controller
    vc.restorationIdentifier = [identifierComponents lastObject];
    
    // If there is only 1 identifier component, then this is the root view controller
    if ([identifierComponents count] == 1) {
        self.window.rootViewController = vc;
    }
    return vc;
}

@end

#8

You’re missing the following method in your code:

[code]- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];

return YES;

}
[/code]

If you read the section under “State Restoration Life Cycle”, in the State Restoration chapter, that’s where the book tells you to add it to BNRAppDelegate.m. The ‘window’ object was not being created.