Crash on iOS9 using [NSPsistentStoreCoordinator _coordinator_you_never_successfully_open_the_database_device_locked:]

My app recently got these crash tests that only happen on iOS9

Fatal exception: NSInternalInconsistency exception
This NSPersistentStoreCoordinator does not have persistent storage (corrupted file). It cannot perform a save operation.

Last call from report

-[NSPersistentStoreCoordinator _coordinator_you_never_successfully_opened_the_database_device_locked:]

and this is how NSPsistentStoreCoordinator is created

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

    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

    NSURL *storeURL = [[delegate applicationDocumentsDirectory] URLByAppendingPathComponent:@"database.sqlite"];

    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel];

    NSError* error = nil;

    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
                                                   configuration:nil
                                                             URL:storeURL
                                                         options:@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} error:&error])
    {
        NSLog(@"Error adding persistent store. %@, %@", error, error.userInfo);
        return nil;
    }

    return _persistentStoreCoordinator;
}

Does anyone know what could cause these accidents?

+4
source share
2 answers

iOS9. , , . , " " PSC?

, - , PSC, , .

, _persistentStoreCoordinator , . , - , , PSC .

, , PSC.

- . , , , . , , , PSC.

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

    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    NSURL *storeURL = [[delegate applicationDocumentsDirectory]
        URLByAppendingPathComponent:@"database.sqlite"];

    NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc]
        initWithManagedObjectModel:self.managedObjectModel];
    NSError *error = nil;
    if (![psc addPersistentStoreWithType:NSSQLiteStoreType
                           configuration:nil
                                     URL:storeURL
                                 options:@{NSMigratePersistentStoresAutomaticallyOption:@YES,
                                           NSInferMappingModelAutomaticallyOption:@YES}
                                   error:&error]) {
        NSLog(@"Error adding persistent store. %@, %@", error, error.userInfo);
    } else {
        _persistentStoreCoordinator = psc;
    }

    return _persistentStoreCoordinator;
}

, , .

@JodyHagins - , , , , ? - AWillian

, , , Xcode . - , , -, .

, " ", , , ( , ).

, , , , , , .

, , , , ... ... -. , , - , ( NSManagedObjectContext, ). , , , - . , , , .

, ?

, - , SO, . , - /, PSC, PSC, .

-, . , , .

MOC , - ...

+ (void)createWithConcurrencyType:(NSManagedObjectContextConcurrencyType)concurrencyType
                       completion:(void(^)(NSManagedObjectContext *moc, NSError *error))completion;

MOM PSC, PSC MOC. , . performBlock, MOC . , MOC , .

concurrency, , .

MOC .

+3

Apple dev , .

: , , API .

, iOS, , , .

-

, , , Core Data , applicationProtectedDataDidBecomeAvailable.

+2

Source: https://habr.com/ru/post/1612528/


All Articles