Custom Core Data Metadata Not Saved for iCloud Storage

I am trying to save some user metadata in iCloud server Core Data SQLite. The documentation apparently says that in addition to the metadata it creates, I should be able to set my own metadata, similar to NSUserPreferences, but attached to my master data repository. Looks like it should be simple:

NSManagedObjectContext* moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[moc setPersistentStoreCoordinator:psc];

NSMutableDictionary* metadata = [[psc metadataForPersistentStore:store] mutableCopy];
metadata[@"testKey"] = @"testValue";
[psc setMetadata:metadata forPersistentStore:store];
[moc save:&error];

So, after that, my user key / metadata value is displayed in the store metadata field. However, when I restart the application, the metadata that I added no longer exists (but there is iCloud metadata). Please note that this works correctly when using regular storage without iCloud, therefore it is defined as iCloud.

Additional Information:

So, let's say I get metadata, add my custom fields and save them using static methods:

[NSPersistentStoreCoordinator setMetadata:metadata forPersistentStoreOfType:NSSQLiteStoreType URL:self.coreDataController.iCloudStore.URL error:&error];
NSDictionary* reviewMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:self.coreDataController.iCloudStore.URL error:&error];

The variable reviewMetadatacontains metadata with my fields added. However, as soon as I restart the application (and therefore reload the repository), it will return to how it was. I even tried to set a breakpoint and kill the application immediately after completing the above statements, and when I restart the application, my user metadata still disappeared.

Any ideas? Am I using metadata incorrectly? Does this work with iCloud-enabled vaults?

+4
source share
2 answers

, OS X. iOS.

- (void)setiCloudMetaDataForStore:(NSURL*)fileURL ofType:(NSString *)fileType iCloud:(bool)iCloudEnabled ubiquityName:(NSString*)ubiquityName {
    //LOG(@"setiCloudMetaDataForStore called...");

    NSError *error;
    NSDictionary *metaData = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:fileType URL:fileURL error:&error];

    if (!metaData) {
        FLOG(@" problem getting metaData");
        FLOG(@"  - error is %@, %@", error, error.userInfo);
    }

    //FLOG(@" metaData is %@", metaData);

    //Now see if we can add a setting to indicate it is iCloud enabled
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:metaData];

    [dict setObject:[[NSNumber alloc] initWithBool:iCloudEnabled] forKey:@"iCloudEnabled"];

    if (!iCloudEnabled)
        [dict removeObjectForKey:NSPersistentStoreUbiquitousContentNameKey];
    else
        [dict setObject:ubiquityName forKey:NSPersistentStoreUbiquitousContentNameKey];

    bool result = [NSPersistentStoreCoordinator setMetadata:dict forPersistentStoreOfType:fileType URL:fileURL error:&error];

    if (!result) {
        FLOG(@" problem setting metaData");
        FLOG(@"  - error is %@, %@", error, error.userInfo);
    }

    return;
}
0

, () -wal -shm, , , sqlite. .sqlite, sqlite:

NSDictionary *options = @{NSSQLitePragmasOption:@{@"journal_mode":@"DELETE"}};

-wal -shm , .sqlite.

0

All Articles