Using Pre-Existing NSFileManager Code with iCloud

I just wrote a few hundred lines of code for saving files, opening files, and deleting files in my iOS app... then I realized that I probably should've explored iCloud and integrated it as I was writing my code.

Is there any way to integrate iCloud into a pre-existing Documents structure, nsfilemanager class, etc.? Or will I have to re-write most of my code from the ground up?

Also, either way, are there any iCloud Projects out there (similar to this one) that would allow me to easily integrate iCloud Document Sync?


Just a quick sample of some code I'm using:

//Begin saving file
NSLog(@"Began Saving File");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:filetitle];

//Get the user's keyword preference
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL enabled = [defaults boolForKey:@"completeFile"];

[[NSString stringWithFormat:@"Message:%@", MessageText] writeToFile:filePath atomically:TRUE encoding:NSUTF8StringEncoding error:NULL];

EDIT: I have created a project on GitHub called iCloud Document Sync that allows developers to easily integrate iCloud with their document-based iOS apps. The problem is that it doesn't really follow the design / structure that normal iCloud files undergo:

  1. File Copied to iCloud
  2. File is then edited locally and changes are uploaded to iCloud
  3. Somehow we must check if the local file is older than the one in iCloud

My GitHub project somewhat solves the problem of this question, but I can't figure out how to copy files from a local directory instead of moving them. The second problem I'm having is figuring out how to edit that local file and push changes - when I try to push changes to a file in the cloud I get a Cocoa Error that says:

Cocoa Error 516: File Exists

Finally, I'm not sure how to check for discrepancies / conflicts between local and cloud files. I think the issue is with the design and flow of the code - however I think that the layout of the code is needed due to the scenario.


EDIT: I read this SO question, which seems to be part of what I'm asking, however I'd like to offer a bounty for a clearer and more well-defined answer.

Answers


This might be of some help. This is how apple describes this in their documentation. https://developer.apple.com/library/mac/#documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesigningForDocumentsIniCloud.html#//apple_ref/doc/uid/TP40012094-CH2-SW1


Need Your Help

Convert binary to varchar on button click

asp.net sql sql-server visual-studio

I'm trying to create a registration page for an SQL server, and I have some problems when it comes to the login section. The column Passphrase is set to dataType Binary(20). When a user registers an