ICloud loadFromContents - how to work with UIDocumentStateSavingError and UIDocumentStateEditingDisabled

I use iCloud in my application to download text files. When downloading text files, this method is called by iCloud when called _UIDocument openWithCompletionHandler:^(BOOL success), etc.:

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

    NSLog(@"Library loadFromContents: state = %d", self.documentState);

 if (!_books) {
        _books = [[NSMutableArray alloc] init];
    }

    //if (self.documentState > 7) {
    //    NSLog(@"document is either savingError (4), EditingDisabled (8) or both (12)... will not load");
    //    return NO;
    //}

    self.books = [NSKeyedUnarchiver unarchiveObjectWithData:contents];

    if ([_delegate respondsToSelector:@selector(libraryDocumentUpdated:)]) {
        [_delegate libraryDocumentUpdated:self];
    }

    return YES;
}

Currently, the big problem is that documentState has a value of 8 (UIDocumentStateEditingDisabled) or 12 (UIDocumentStateSavingError and UIDocumentStateEditingDisabled). This usually causes the application to crash. I tried to return NO if documentState> 7, i.e. If it is 8 or 12, but this leads to the fact that the content does not load at all.

I think the problem is that UIDocument will not load anything in self.books if editing is disabled or if a save error occurs.

? , Apple State UIDocument (iCloud Docs)? , - .

+5
1

?

, , ,

[NSFileVersion unresolvedConflictVersionsOfItemAtURL:]

, , ,

[NSFileManager evictUbiquitousItemAtURL:]

[NSFileManager startDownloadingUbiquitousItemAtURL:]

, .

+4

All Articles