To further my basic learning, I've read quite a lot over the past few days on adding iCloud back-up and/or more advanced syncing features to an existing app which uses UIManagedDocument to get its Core Data stack. I'm seeing that some people are referring to updates in iOS 7 that make many of the articles (and Apple's own documentation) from 2011 and 2012 (which seem to be the most common dates on most of what's written [discovered via google searching]) somewhat "obsolete". In general, where does adding iCloud support in an app stand as of May 2014? Answers seem to range from "with UIManagedDoc I only added a few lines of code" to many more involved examples that utilize more advanced notifications of changes to data both locally and in the cloud.
What I can't yet wrap my head around is where does one start, as of right now, when adding iCloud basic back-up across iCloud enabled devices (simulator included now for basic tests, apparently)? Say, if looking at code based on the Stanford Core Data lectures (see below), what are the steps needed to add iCloud syncing? What exactly has actually changed with iOS 7 to simplify this?
Do under-the-hood updates to iOS 7 really only require a "few lines" of code to get the code below ready for basic iCloud support?
I'm trying to get my head around what is the best practice, as of right now, to approach basic iCloud support in an app that used a UIManagedDocument. What changes to the code below, which already creates a doc in the Documents directory and uses that single document, need to be done?
Apple's own documentation hasn't been much help to me. I think I just need to see addition to code that I already understand to get me a point of reference.
From The Hegarty lectures, Stanford:
-(void)useDemoDocument
{
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:@"Demo Document"];
UIManagedDocument *document = [[UIManagedDocument alloc] initWithFileURL:url];
if (![[NSFileManager defaultManager] fileExistsAtPath:[url path]]) {
//create
[ document saveToURL:url
forSaveOperation:UIDocumentSaveForCreating
completionHandler:^(BOOL success) {
if (success) {
self.context = document.managedObjectContext;
}
}];
} else if (document.documentState == UIDocumentStateClosed){
//open
[document openWithCompletionHandler:^(BOOL success) {
if (success) {
self.context = document.managedObjectContext;
//[self refresh];
}
}];
} else {
//try to use it
self.context = document.managedObjectContext;
}
}