Skip to content

Commit 137840a

Browse files
Merge pull request #1457 from twinkles-twinstar/master
fix #1412: Picking a folder in iOS causes the original folder to be deleted.
2 parents 0fb60c9 + 0c245b0 commit 137840a

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 8.0.2
2+
### iOS
3+
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.
4+
15
## 8.0.1
26
### iOS
37
Fixes an issue preventing compilation on iOS when using Pod::PICKER_DOCUMENT = false.

ios/Classes/FilePickerPlugin.m

+23-17
Original file line numberDiff line numberDiff line change
@@ -400,27 +400,33 @@ - (void)documentPicker:(UIDocumentPickerViewController *)controller
400400
_result = nil;
401401
return;
402402
}
403-
NSMutableArray<NSURL *> *newUrls = [NSMutableArray new];
404-
for (NSURL *url in urls) {
405-
// Create file URL to temporary folder
406-
NSURL *tempURL = [NSURL fileURLWithPath:NSTemporaryDirectory()];
407-
// Append filename (name+extension) to URL
408-
tempURL = [tempURL URLByAppendingPathComponent:url.lastPathComponent];
409-
NSError *error;
410-
// If file with same name exists remove it (replace file with new one)
411-
if ([[NSFileManager defaultManager] fileExistsAtPath:tempURL.path]) {
412-
[[NSFileManager defaultManager] removeItemAtPath:tempURL.path error:&error];
403+
NSMutableArray<NSURL *> *newUrls;
404+
if(controller.documentPickerMode == UIDocumentPickerModeOpen) {
405+
newUrls = urls;
406+
}
407+
if(controller.documentPickerMode == UIDocumentPickerModeImport) {
408+
newUrls = [NSMutableArray new];
409+
for (NSURL *url in urls) {
410+
// Create file URL to temporary folder
411+
NSURL *tempURL = [NSURL fileURLWithPath:NSTemporaryDirectory()];
412+
// Append filename (name+extension) to URL
413+
tempURL = [tempURL URLByAppendingPathComponent:url.lastPathComponent];
414+
NSError *error;
415+
// If file with same name exists remove it (replace file with new one)
416+
if ([[NSFileManager defaultManager] fileExistsAtPath:tempURL.path]) {
417+
[[NSFileManager defaultManager] removeItemAtPath:tempURL.path error:&error];
418+
if (error) {
419+
NSLog(@"%@", error.localizedDescription);
420+
}
421+
}
422+
// Move file from app_id-Inbox to tmp/filename
423+
[[NSFileManager defaultManager] moveItemAtPath:url.path toPath:tempURL.path error:&error];
413424
if (error) {
414425
NSLog(@"%@", error.localizedDescription);
426+
} else {
427+
[newUrls addObject:tempURL];
415428
}
416429
}
417-
// Move file from app_id-Inbox to tmp/filename
418-
[[NSFileManager defaultManager] moveItemAtPath:url.path toPath:tempURL.path error:&error];
419-
if (error) {
420-
NSLog(@"%@", error.localizedDescription);
421-
} else {
422-
[newUrls addObject:tempURL];
423-
}
424430
}
425431

426432
[self.documentPickerController dismissViewControllerAnimated:YES completion:nil];

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
33
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
44
repository: https://github.com/miguelpruivo/flutter_file_picker
55
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
6-
version: 8.0.1
6+
version: 8.0.2
77

88
dependencies:
99
flutter:

0 commit comments

Comments
 (0)