Post

Replies

Boosts

Views

Activity

Reply to UIDocumentPicker Error on accession selected file
@eskimo The file I'm trying to access is a custom file (created with UIDocument and NSFileWrapper) from another applications of mine. I added the support to this new app I'm developing to open those files, but even through the "open in" functionality directly from File app I get always the same error. I checked the code of the other project but I don't see any restriction created directly by me. From the other app I can zip and export the file, in that case my new app can open the exported file without any issue. There is something I'm missing or that I'm not aware of? Here there is the code from the other project, this is from the UIDocument subclass: (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError *__autoreleasing *)outError{     _fileWrapper = (NSFileWrapper*)contents;     // The rest will be lazy loaded inside getter methods     return YES; } (id)contentsForType:(NSString *)typeName error:(NSError *__autoreleasing *)outError{     if (_fileWrapper == nil) {         NSLog(@"NIL WRAPPER");         _fileWrapper = [[NSFileWrapper alloc]initDirectoryWithFileWrappers:nil];     }     NSDictionary *fileWrappers = [_fileWrapper fileWrappers];     [self encodeString:_name forKey:kName insideDictionary:fileWrappers]; 		//all other property of the document     return _fileWrapper; } //pragma mark - HELPERs (void)encodeString:(NSString*)string forKey:(NSString*)key insideDictionary:(NSDictionary*)wrapperDic{     if (([wrapperDic objectForKey:key] == nil) && (string != nil)) {         NSData *textData = [string dataUsingEncoding:NSUTF8StringEncoding];         NSFileWrapper *textFileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:textData];         [textFileWrapper setPreferredFilename:key];         [_fileWrapper addFileWrapper:textFileWrapper];     } } (void)encodeData:(NSData*)imageData forKey:(NSString*)key insideDictionary:(NSDictionary*)wrapperDic{     if (([wrapperDic objectForKey:key] == nil) && (imageData != nil)) {         @autoreleasepool {             NSFileWrapper *imageFileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:imageData];             [imageFileWrapper setPreferredFilename:key];             [_fileWrapper addFileWrapper:imageFileWrapper];         }     } }
Jul ’20
Reply to UIDocumentPicker Error on accession selected file
and this is the file creation: RecipeDocument* newDoc = [[RecipeDocument alloc]initWithFileURL:newURL];     newDoc.name = recipe.name; //all other property of the document     [newDoc saveToURL:newURL      forSaveOperation:UIDocumentSaveForCreating     completionHandler:^(BOOL success) { this is the code that moves the file to iCloud: (void)moveFileToiCloud:(RecipeDocument *)fileToMove {     NSURL *sourceURL = fileToMove.fileURL;     NSString *destinationFileName = fileToMove.fileURL.lastPathComponent;     NSURL *destinationURL = [[[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]URLByAppendingPathComponent:@"Documents"] URLByAppendingPathComponent:destinationFileName];     if ([[NSFileManager defaultManager]fileExistsAtPath:[NSString stringWithFormat:@"%@",destinationURL]]) {         NSLog(@"FILE EXIST");         //Check per sapere se esiste già un file in cloud, nel caso cancello quello in locale         RecipeDocument* check = [[RecipeDocument alloc]initWithFileURL:destinationURL];         [check openWithCompletionHandler:^(BOOL success) {             if (success) {                 [self deleteRecipe:[[RecipeModel alloc]initWithDocument:fileToMove atURL:sourceURL] docAtURL:sourceURL];                 return;             }         }];     }     dispatch_queue_t q_default;     q_default = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);     dispatch_async(q_default, ^(void) {         NSFileManager *fileManager = [[NSFileManager alloc] init];         NSError *error = nil;         BOOL success = [fileManager setUbiquitous:YES                                         itemAtURL:sourceURL                                    destinationURL:destinationURL                                             error:&error];         dispatch_queue_t q_main = dispatch_get_main_queue();         dispatch_async(q_main, ^(void) {          if (success) {                 NSLog(@"SUCCESS to move file to iCloud: %@", fileToMove.name);             }             if (!success) {                 NSLog(@"FAILED to move file to iCloud: %@", fileToMove.name);             }         });     }); } Thank you for your help.
Jul ’20