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 MyDocument *doc = [[MyDocument alloc] initWithFileURL:ubiquitousFileURL]; [doc openWithCompletionHandler:^(BOOL success) { if (success) {
... and this while saving:
- (void)saveToURL:(NSURL *)url forSaveOperation:(UIDocumentSaveOperation)saveOperation completionHandler:(void (^)(BOOL success))completionHandler MyDocument *doc = [[MyDocument alloc] initWithFileURL:ubiquitousPackage]; [doc saveToURL:[doc fileURL] forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) { if (success) {
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.
source share