简体   繁体   中英

App Crashes at startup on App Store review - works perfectly on devices

I have an app that crashes on startup in the app store review, but works perfectly otherwise on devices and on the simulators. Here are the specifics.

The app is written for IOS 7, and is being tested on IOS 8.x. I symbolicated the crash logs from Apple, and it is crashing on the first attempt to access information stored in the pre-populated Core Data sqlite db.

This code does the db copy at startup:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil)
    {
        return __persistentStoreCoordinator;
    }

    NSURL *storeURL = [[self applicationDocumentsDirectory]     URLByAppendingPathComponent:@"CC.sqlite"];
    NSArray *paths =     NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *storePath = [documentsDirectory     stringByAppendingPathComponent: @"CC.sqlite"];

    // Check if the sqlite store exists
    if (![[NSFileManager defaultManager] fileExistsAtPath:storePath]) {
        NSLog(@"sqlite db not found... copy into place");

        // copy the sqlite files to the store location.
        NSString *bundleStore = [[NSBundle mainBundle]    pathForResource:@"CC" ofType:@"sqlite"];
         [[NSFileManager defaultManager] copyItemAtPath:bundleStore     toPath:storePath error:nil];

    }
    else {
        NSLog(@"Already exists");
    }
    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator     alloc] initWithManagedObjectModel:[self managedObjectModel]];
    NSDictionary *options = @{ NSSQLitePragmasOption :     @{@"journal_mode" : @"DELETE"} };


    if (![__persistentStoreCoordinator     addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL     options:options error:&error])
    {
                NSLog(@"error %@, %@", error, [error userInfo]);

    }

    return __persistentStoreCoordinator;
}

We have run this a couple of hundred times on various IOS devices (by several different people) without any problems at all, but invariably get a startup crash at Apple.

It is clear to me from the crash logs that the app (during app store review) is trying to access a non-existant sqlite db through Core Data, but I have no idea why this is happening only at Apple, and why I cannot reproduce the error. I am not sure what other info to add to the question but will happily update as required.

Any advice gratefully received....

I will answer my own question here, although the code changes I made while trying to solve the problem makes posting the code not very helpful.

I had to put the startup database operations in a completion block. This involved moving everything into my initial startup view controller, and disabling my tab bar buttons while the database was initialized.

What was happening was certain items in the Core Data sqlite database were being required before it was completely preloaded, thus the crash.

More on blocks can be found here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM