diff --git a/CHANGELOG.md b/CHANGELOG.md index 82aaa216..5bbce0a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 8.0.2 +### iOS +Fixes the bug [#1412](https://github.com/miguelpruivo/flutter_file_picker/issues/1412) that picking a folder in iOS causes the original folder to be deleted. + ## 8.0.1 ### iOS Fixes an issue preventing compilation on iOS when using Pod::PICKER_DOCUMENT = false. diff --git a/ios/Classes/FilePickerPlugin.m b/ios/Classes/FilePickerPlugin.m index 7e2a869d..09b36cab 100644 --- a/ios/Classes/FilePickerPlugin.m +++ b/ios/Classes/FilePickerPlugin.m @@ -400,27 +400,33 @@ - (void)documentPicker:(UIDocumentPickerViewController *)controller _result = nil; return; } - NSMutableArray *newUrls = [NSMutableArray new]; - for (NSURL *url in urls) { - // Create file URL to temporary folder - NSURL *tempURL = [NSURL fileURLWithPath:NSTemporaryDirectory()]; - // Append filename (name+extension) to URL - tempURL = [tempURL URLByAppendingPathComponent:url.lastPathComponent]; - NSError *error; - // If file with same name exists remove it (replace file with new one) - if ([[NSFileManager defaultManager] fileExistsAtPath:tempURL.path]) { - [[NSFileManager defaultManager] removeItemAtPath:tempURL.path error:&error]; + NSMutableArray *newUrls; + if(controller.documentPickerMode == UIDocumentPickerModeOpen) { + newUrls = urls; + } + if(controller.documentPickerMode == UIDocumentPickerModeImport) { + newUrls = [NSMutableArray new]; + for (NSURL *url in urls) { + // Create file URL to temporary folder + NSURL *tempURL = [NSURL fileURLWithPath:NSTemporaryDirectory()]; + // Append filename (name+extension) to URL + tempURL = [tempURL URLByAppendingPathComponent:url.lastPathComponent]; + NSError *error; + // If file with same name exists remove it (replace file with new one) + if ([[NSFileManager defaultManager] fileExistsAtPath:tempURL.path]) { + [[NSFileManager defaultManager] removeItemAtPath:tempURL.path error:&error]; + if (error) { + NSLog(@"%@", error.localizedDescription); + } + } + // Move file from app_id-Inbox to tmp/filename + [[NSFileManager defaultManager] moveItemAtPath:url.path toPath:tempURL.path error:&error]; if (error) { NSLog(@"%@", error.localizedDescription); + } else { + [newUrls addObject:tempURL]; } } - // Move file from app_id-Inbox to tmp/filename - [[NSFileManager defaultManager] moveItemAtPath:url.path toPath:tempURL.path error:&error]; - if (error) { - NSLog(@"%@", error.localizedDescription); - } else { - [newUrls addObject:tempURL]; - } } [self.documentPickerController dismissViewControllerAnimated:YES completion:nil]; diff --git a/pubspec.yaml b/pubspec.yaml index da23f74e..2a344f82 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker repository: https://github.com/miguelpruivo/flutter_file_picker issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues -version: 8.0.1 +version: 8.0.2 dependencies: flutter: