Skip to content

Commit

Permalink
Merge pull request #1693 from orestesgaolin/spectorasoftware/master
Browse files Browse the repository at this point in the history
Fix Picking live photos on iOS
  • Loading branch information
navaronbracke authored Jan 29, 2025
2 parents 83bdfc9 + 728b949 commit a74f892
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.3.1
### iOS
- Fix [1367](https://github.com/miguelpruivo/flutter_file_picker/issues/1367)

## 8.3.0
### Desktop (macOS) && iOS
- Adds support for Swift Package Manager for compatibility with new projects [#1582](https://github.com/miguelpruivo/flutter_file_picker/issues/1582)
Expand Down
2 changes: 1 addition & 1 deletion example/android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
eclipse.preferences.version=1
23 changes: 22 additions & 1 deletion ios/file_picker/Sources/file_picker/FilePickerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ @interface FilePickerPlugin()
@property (nonatomic) BOOL loadDataToMemory;
@property (nonatomic) BOOL allowCompression;
@property (nonatomic) dispatch_group_t group;
@property (nonatomic) MediaType type;
@property (nonatomic) BOOL isSaveFile;
@end

Expand Down Expand Up @@ -230,6 +231,8 @@ - (void)resolvePickDocumentWithMultiPick:(BOOL)allowsMultipleSelection pickDirec

#ifdef PICKER_MEDIA
- (void) resolvePickMedia:(MediaType)type withMultiPick:(BOOL)multiPick withCompressionAllowed:(BOOL)allowCompression {

self.type = type;

#ifdef PHPicker
if (@available(iOS 14, *)) {
Expand Down Expand Up @@ -528,19 +531,37 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke
__block NSInteger completedCount = 0;
NSInteger totalCount = results.count;

bool isImageSelection = self.type == IMAGE;
bool isMediaSelection = self.type == MEDIA;
for (NSInteger index = 0; index < results.count; ++index) {
dispatch_group_enter(_group);
PHPickerResult * result = [results objectAtIndex:index];

dispatch_async(processQueue, ^{
@autoreleasepool {
if (isMediaSelection) {
if (![result.itemProvider hasItemConformingToTypeIdentifier:@"public.image"] &&
![result.itemProvider hasItemConformingToTypeIdentifier:@"public.movie"]) {
[errors addObject:[NSString stringWithFormat:@"Item at index %ld is not an image or video", (long)index]];
dispatch_group_leave(self->_group);
return;
}
} else if (isImageSelection) {
if (![result.itemProvider hasItemConformingToTypeIdentifier:@"public.image"]) {
[errors addObject:[NSString stringWithFormat:@"Item at index %ld is not an image", (long)index]];
dispatch_group_leave(self->_group);
return;
}
}

[result.itemProvider loadFileRepresentationForTypeIdentifier:@"public.image" completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {
NSString *typeIdentifier;
if ([result.itemProvider hasItemConformingToTypeIdentifier:@"public.image"]) {
typeIdentifier = @"public.image";
} else {
typeIdentifier = @"public.movie";
}

[result.itemProvider loadFileRepresentationForTypeIdentifier:typeIdentifier completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {
@autoreleasepool {
if (error != nil || url == nil) {
[errors addObject:[NSString stringWithFormat:@"Failed to load image at index %ld: %@",
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.0
version: 8.3.1

dependencies:
flutter:
Expand Down

0 comments on commit a74f892

Please sign in to comment.