Sync .plist file with iCloud

I'm trying to figure out how to sync the .plist file that I have in the Application Support folder in my Sandboxed application for Mac. I know that I could use the iCloud key value store, but there is a 64K limit per application that may or may not suffer depending on how much the user adds to the application!

I read as much Apple documentation as possible, but I'm still rather confused :(

Does anyone do something like this?

thanks

+4
source share
1 answer

You must subclass UIDocument and use it with ubiquity directories.

There are 2 methods for processing read / write. This call is invoked while reading:

 - (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError **)outError 

And this is when writing:

 - (id)contentsForType:(NSString *)typeName error:(NSError **)outError 

All open / save actions are called automatically, you do not need to do anything. However, there are methods that force open / save. Call this on opening:

 - (void)openWithCompletionHandler:(void (^)(BOOL success))completionHandler /* --- EXAMPLE --- */ MyDocument *doc = [[MyDocument alloc] initWithFileURL:ubiquitousFileURL]; [doc openWithCompletionHandler:^(BOOL success) { if (success) { // do sth } else { // handle error } }]; 

... and this while saving:

 - (void)saveToURL:(NSURL *)url forSaveOperation:(UIDocumentSaveOperation)saveOperation completionHandler:(void (^)(BOOL success))completionHandler /* --- EXAMPLE --- */ MyDocument *doc = [[MyDocument alloc] initWithFileURL:ubiquitousPackage]; [doc saveToURL:[doc fileURL] forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) { if (success) { // do sth } else { // handle error } }]; 

There are many tutorials on the Internet, here are a few examples that I used for training:

A reference to the UIDocument class can also help.

+3
source

Source: https://habr.com/ru/post/1387947/


All Articles