Implementation discussion: db sharing with watchOS 2
We currently use the default CoreData settings in respect to SQLite settings. Since iOS 7 the SQLite write ahead log is enabled by default. Which adds an extra -wal file next to the sqlite db.
Since I only want to copy a single file to the Watch instead of multiple files which depend on each other I tried to use the new iOS 9 method
-[NSPersistentStoreCoordinator replacePersistentStoreAtURL:destinationOptions:withPersistentStoreFromURL:sourceOptions:storeType:error:]
According to the header file for "SQLite stores [it] will honor file locks, journal files, journaling modes, and other intricacies."
Since destination options and source options can be set independently i though that with the destination options:
destOptions[NSSQLitePragmasOption] = @{@"journal_mode": @"DELETE"};
the copied sqlite would not use any -wal files.
The next approach was to create an second NSPersistentStoreCoordinator and migratePersistentStore:toURL:options:withType:error: with the same options. Indeed, the destination store was no longer user the wal file. But now we have an unexpected new problem: since we migrated the persistent store, the URIRepesentation of the objects differs since the persistent store has a new UUID. Therefore we can see files on the watch but no longer open files from there because the URIRepresentation sent from the watch is not known to the persistent store coordinator on the iPhone.
I can think of two possible solutions:
- Disable wal by default in MLMediaLibrary
- Rewrite URIRepresentations to the iPhone persistent store UUID.
What are your thought on the options? Do you have any other ideas?