Reputation: 932
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:
The operation couldn’t be completed. (BRCloudDocsErrorDomain error 2 - Logged out - iCloud Drive is not configured)
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.
Upvotes: 3
Views: 1400
Reputation: 441
It's possible that the iCloud Debug Gauge does not work for apps running in the simulator because it doesn't have full functionality. This is from 2014, so things may have changed.
However, iCloud Core Data is not fully supported in the simulator. When testing across devices and the simulator, it seems that iCloud Core Data on the simulator only uploads changes, and never pulls them back down. This is still a big improvement over needing separate test devices, and a nice convenience, but iCloud Core Data support on the iOS Simulator is definitely not fully baked yet.
http://www.objc.io/issues/10-syncing-data/icloud-core-data/
The only thing I can find about it in official documentation says:
It is especially important to test an iCloud-enabled iOS app on an actual device. iOS Simulator doesn’t accurately simulate the use of iCloud under real-world conditions.
Upvotes: 1