Can't create externalDataReference interim file

冷暖自知 提交于 2019-12-01 14:23:49

I use a similar process in my app, with two contexts set during the construction of my core data stack and using:

  • NSPrivateQueueConcurrencyType,
  • NSMainQueueConcurrencyType.

To take a guess, the blocks may be conflicting with the operation of the notification, however that is a guess.

For my app I've modified the solution presented by Marcus Zarra in his book from The Pragmatic Bookshelf – "Core Data, 2nd Edition, Data Storage and Management for iOS, OS X, and iCloud" (Jan 2013).

For a more up to date and all encompassing solution that I have not yet implemented, read this article My Core Data Stack by Zarra.

My modified solution involves writing a custom save method built alongside (in the same class as) my core data stack, shown following, instead of using a NSManagedObjectContextObjectsDidChangeNotification. Note that the save method is called at appropriate points in code.

Maybe this is a suitable alternative?

Properties...

@property (nonatomic, strong) NSManagedObjectContext *mocPrivate;
@property (nonatomic, strong) NSManagedObjectContext *mocMain;

Custom save method...

- (void)saveContextAndWait:(BOOL)wait {
    if ([self.mocMain hasChanges]) {
        [self.mocMain performBlockAndWait:^{
            NSError __autoreleasing *error;
            BOOL success;
            if (!(success = [self.mocMain save:&error]))
                NSLog(@"%@ - %@ - CORE DATA - E~R~R~O~R saving managedObjectContext MAIN: %@, %@", NSStringFromClass(self.class), NSStringFromSelector(_cmd), error.localizedDescription, error.localizedFailureReason);
            NSLog(@"%@ - %@ - CORE DATA - Success saving managedObjectContext MAIN?: %@", NSStringFromClass(self.class), NSStringFromSelector(_cmd), success ? @"YES_" : @"NO_");
        }];
    }

    void (^savePrivate) (void) = ^{
        NSError __autoreleasing *error;
        BOOL success;
        if (!(success = [self.mocPrivate save:&error]))
            NSLog(@"%@ - %@ - CORE DATA - E~R~R~O~R saving managedObjectContext PRIVATE: %@, %@", NSStringFromClass(self.class), NSStringFromSelector(_cmd), error.localizedDescription, error.localizedFailureReason);
        NSLog(@"%@ - %@ - CORE DATA - Success saving managedObjectContext PRIVATE?: %@", NSStringFromClass(self.class), NSStringFromSelector(_cmd), success ? @"YES_" : @"NO_");
    };

    if ([self.mocPrivate hasChanges]) {
        if (wait) {
            [self.mocPrivate performBlockAndWait:savePrivate];
        } else {
            [self.mocPrivate performBlock:savePrivate];
        }
    }
}

I have managed to reproduce this issue by filling up entire disk space on the device and then using the app, storing media in Core Data.

After some time using the app, a warning popup shows that the device is low on disk space. I dismiss the warning and continue to use the app. After some additional time, the app crashes with the message:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can't create externalDataReference interim file : 28'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!