Remove Core Data from iCloud fails

你。 提交于 2019-12-06 08:28:38

Normally (before iOS7), you take the ubiquitousContentURL value from [fileManager URLForUbiquityContainerIdentifier:nil]; and pass it as an option called NSPersistentStore UbiquitousContentURLKey, and this is how iCloud know where to keep all of your data in the iCloud account.

In iOS 7 and Mac OS X we don't need to pass a value for that at all, and Apple call URLForUbiquitous ContainerIdentifier automatically under the hood for you.

So the solution looks like this:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:kICloudContentNameKey, NSPersistentStoreUbiquitousContentNameKey, nil];
NSURL *storeURL = [NSPersistentStore MR_urlForStoreName:[MagicalRecord defaultStoreName]];
BOOL result = [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:storeURL options:options error:&error];

I suggest you to check WWDC 2013 session 207 to get this things clearly.

NSCocoaErrorDomain error 513 is defined in FoundationErrors.h as NSFileWriteNoPermissionError. You don't have the required permissions to write to the location.

This can happen if a managed object context is still using objects that are backed by this store. The context is actively using the file that is being moved, which results in a NSFileCoordinator conflict. Two things are trying to access the file with write permission at the same time.

The removeUbiquitousContentAndPersistentStoreAtURL:options:error: method deletes all of the user's local and cloud data—this is probably not what you want. Instead, migrate your store to a new location on disk and use the NSPersistentStoreRemoveUbiquitousMetadataOption option with the migratePersistentStore:toURL:options:withType:error: method.

See Disabling iCloud Persistence at Removing an iCloud-enabled Persistent Store in the iCloud Programming Guide for Core Data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!