I'm trying to add iCloud functionality to an existing app. I'm using UIManagedDocument to reference Core Data. I've put a fair amount of research into this and I can't figure out what I'm doing wrong.
I've tried getting this to work on my Macbook and on my Mac Mini. I've tried turning off the iCloud capability, exiting Xcode, then reopening Xcode and turning iCloud capability back on. No luck.
The reason why I don't think it's entitled is because:
- I'm not seeing the Cloud Debug Gauge.
- When I trigger an iCloud sync in the simulator I get an error stating:
The operation couldn’t be completed. (BRCloudDocsErrorDomain error 2 - Logged out - iCloud Drive is not configured)
- The following resolves to
nil
.
[[NSFileManager defaultManager] ubiquityIdentityToken]
Setup Screenshots
The iCloud Capability is setup.
The App ID has iCloud turned on.
My provisioning profile says it's setup for iCloud. I also revoked and reauthorized when I switched over to my Mac Mini.
I saw a post about Xcode 6 beta not having entitlements setup correctly, however near as I can tell this is ok. I did try changing the Ubiquity Container Identifier to $(TeamIdentifierPrefix)$(CFBundleIdentifier)
but it didn't seem to make a difference.
Code
Maybe the problem is with my code? The only new part below is NSPersistentStoreUbiquitousContentNameKey: @"iCloudStore"
.
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] firstObject];
url = [url URLByAppendingPathComponent:DATABASE_DOCUMENT_NAME];
self.document = [[UIManagedDocument alloc] initWithFileURL:url];
// To cause light-weight model version migration to occur.
self.document.persistentStoreOptions = @{
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES,
NSPersistentStoreUbiquitousContentNameKey: @"iCloudStore"
};
After the code above it's either performing openWithCompletionHandler
or saveToURL:url forSaveOperation:UIDocumentSaveForCreating
. I am also registered to be notified about NSPersistentStoreCoordinatorStoresDidChangeNotification
and that is happening.