开发者

iOS: What errors can be caused by NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:

I'm building an iOS app using CoreData. A small number of my users (roughly 1/1000) are reporting that the app crashes shortly 开发者_Go百科after launching. I suspect that the persistent store coordinator is failing to add the database as a persistent store. I've been unable to reproduce any errors in testing and I can't get any debugging info from my users. Does anyone know of any common errors that this method generates?

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

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"databasefile.sqlite"];

    NSError *error = nil;

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

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

    return persistentStoreCoordinator_;
}


You can looked at the Core Data Constants Reference but without any debug data it won't do you much good.

The only thing I could think to check would be: (1) accidentally writing to or overwriting the store somewhere else in code e.g. you intend to back the file up by copying it but instead overwrite it partially. (2) Altering the permissions on the file.

I have seen cases of both those on MacOS but never on iOS. The store is in the documents folder and has a very generic name so conceivably, under iOS 4.x, you could copy a file in on top of it.

Since you haven't done anything fancy with the persistent store , I think it tremendously unlikely that it is the cause of the crash. If you use the standard boilerplate code you are talking about something that is highly tested and refined. I would suspect a resource of some type e.g. an image or audio file, in the app bundle before I would suspect the store.


I think you have added new Attribute to entities and that's why old .sqlite is not getting a match with new.

Solution :

If u got an error like "The model used to open the store is incompatible with the one used to create the store." then just delete DB and create a new one or delete the app and reinstall.

If I'm wrong, please let me know.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜