diff --git a/CHANGELOG.md b/CHANGELOG.md index ee4678c..7e95e0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.1.1 +iOS: Fixes an issue that could result in a crash when selecting a media item twice. ([#518](https://github.com/miguelpruivo/flutter_file_picker/issues/518)). + ## 2.1.0 Adds `withReadStream` that allows bigger files to be streamed read into a `Stream>`. Thanks @redsolver. diff --git a/ios/Classes/FilePickerPlugin.m b/ios/Classes/FilePickerPlugin.m index 0271578..0bed2ae 100644 --- a/ios/Classes/FilePickerPlugin.m +++ b/ios/Classes/FilePickerPlugin.m @@ -14,6 +14,7 @@ @property (nonatomic) MPMediaPickerController *audioPickerController; @property (nonatomic) NSArray * allowedExtensions; @property (nonatomic) BOOL loadDataToMemory; +@property (nonatomic) dispatch_group_t group; @end @implementation FilePickerPlugin @@ -362,6 +363,10 @@ didPickDocumentsAtURLs:(NSArray *)urls{ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray *)results API_AVAILABLE(ios(14)){ + if(self.group != nil) { + return; + } + Log(@"Picker:%@ didFinishPicking:%@", picker, results); [picker dismissViewControllerAnimated:YES completion:nil]; @@ -375,15 +380,15 @@ didPickDocumentsAtURLs:(NSArray *)urls{ NSMutableArray * urls = [[NSMutableArray alloc] initWithCapacity:results.count]; - dispatch_group_t group = dispatch_group_create(); + self.group = dispatch_group_create(); for (PHPickerResult *result in results) { - dispatch_group_enter(group); + dispatch_group_enter(_group); [result.itemProvider loadFileRepresentationForTypeIdentifier:@"public.item" completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) { if(url == nil) { Log("Could not load the picked given file: %@", error); - dispatch_group_leave(group); + dispatch_group_leave(self->_group); return; } @@ -408,11 +413,12 @@ didPickDocumentsAtURLs:(NSArray *)urls{ } [urls addObject:cachedUrl]; - dispatch_group_leave(group); + dispatch_group_leave(self->_group); }]; } - dispatch_group_notify(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{ + dispatch_group_notify(_group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{ + self->_group = nil; [self handleResult:urls]; }); } diff --git a/lib/src/platform_file.dart b/lib/src/platform_file.dart index e8d1f71..1fa810c 100644 --- a/lib/src/platform_file.dart +++ b/lib/src/platform_file.dart @@ -16,8 +16,8 @@ class PlatformFile { this.bytes = data['bytes'], this.size = data['size']; - /// The absolute path for a cached copy of this file. It can be used to create a - /// a file instance with a descriptor for the given path. + /// The absolute path for a cached copy of this file. It can be used to create a + /// file instance with a descriptor for the given path. /// ``` /// final File myFile = File(platformFile.path); /// ``` diff --git a/pubspec.yaml b/pubspec.yaml index b46bd0b..1922288 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: file_picker description: A package that allows you to use a native file explorer to pick single or multiple absolute file paths, with extension filtering support. homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker -version: 2.1.0 +version: 2.1.1 dependencies: flutter: