CoreData AddPersistentStore error 512 on real device

I'm porting an iOS application on tvOS. It uses coredata.

I copied the data management logic with no changes and in the simulator is working fine.

When I attempt to run on real AppleTV I got this error but the application could continue to run and the Sqlite database is working (in readOnly). When I make any change and save the context I have a crash.

Instead, as I told before, in the simulator everything seems working correctly.


============================

2015-09-27 02:31:19.571 Vda3dATV[207:9404] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Containers/Data/Application/6BA4E327-F24E-4E84-ACBE-4C2F33627108/Documents/QuickAround.sqlite options:{

NSInferMappingModelAutomaticallyOption = 1;

NSMigratePersistentStoresAutomaticallyOption = 1;

} ... returned error Error Domain=NSCocoaErrorDomain Code=512 "The file couldn’t be saved." UserInfo={reason=Failed to create file; code = 1} with userInfo dictionary {

reason = "Failed to create file; code = 1";

}

=============================



Any suggestion ?


Thanks


Dario

I discovered the same problem. Works in simulator, crashes on device, "The file couldn’t be saved."

Looks like a beta 2 bug.

Accepted Answer

You need to place the db in NSCachesDirectory instead of NSDocumentDirectory (as in .../Application/XXX/Documents/QuickAround.sqlite).

Great catch! Thanks!

Reminder: AppleTV apps don't have access to permanent, persistent storage. You can put stuff in NSCachesDirectory, but it might get cleared out by the operating system.

It's working !

Thanks

Dario

CoreData AddPersistentStore error 512 on real device
 
 
Q