Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Picking live photos on iOS #1693

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"] &&
navaronbracke marked this conversation as resolved.
Show resolved Hide resolved
![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";
navaronbracke marked this conversation as resolved.
Show resolved Hide resolved
}

[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