Skip to content

Commit 1905069

Browse files
authored
fix[image_picker_ios]: Prevent transcoding on video selection (#10559)
Fixes a severe performance regression where picking videos on iOS could take 10-30+ seconds. The delay was caused by PHPickerViewController defaulting to the Automatic asset representation mode, which triggered slow transcoding for formats like HEVC. This change sets preferredAssetRepresentationMode to Current to provide the original file without conversion, significantly improving performance. Fixes flutter/flutter#176355 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent a4898b6 commit 1905069

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

packages/image_picker/image_picker_ios/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.13+3
2+
3+
* Fixes a performance regression on iOS where picking videos could cause a long delay due to transcoding. The picker is now configured to request the original asset to avoid conversion.
4+
15
## 0.8.13+2
26

37
* Updates to Pigeon 26.

packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerPluginTests.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,4 +701,28 @@ - (void)testPickMultiVideoWithoutLimit {
701701
XCTAssertEqual(plugin.callContext.maxItemCount, 0);
702702
}
703703

704+
- (void)testPickVideoSetsCurrentRepresentationMode API_AVAILABLE(ios(14)) {
705+
id mockPickerViewController = OCMClassMock([PHPickerViewController class]);
706+
OCMStub(ClassMethod([mockPickerViewController alloc])).andReturn(mockPickerViewController);
707+
OCMExpect([mockPickerViewController
708+
initWithConfiguration:[OCMArg checkWithBlock:^BOOL(PHPickerConfiguration *config) {
709+
return config.preferredAssetRepresentationMode ==
710+
PHPickerConfigurationAssetRepresentationModeCurrent;
711+
}]])
712+
.andReturn(mockPickerViewController);
713+
714+
FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc] init];
715+
id partialPlugin = OCMPartialMock(plugin);
716+
id mockViewController = OCMClassMock([UIViewController class]);
717+
OCMStub([partialPlugin viewControllerWithWindow:OCMOCK_ANY]).andReturn(mockViewController);
718+
719+
[plugin pickVideoWithSource:[FLTSourceSpecification makeWithType:FLTSourceTypeGallery
720+
camera:FLTSourceCameraRear]
721+
maxDuration:nil
722+
completion:^(NSString *_Nullable result, FlutterError *_Nullable error){
723+
}];
724+
725+
OCMVerifyAll(mockPickerViewController);
726+
}
727+
704728
@end

packages/image_picker/image_picker_ios/ios/image_picker_ios/Sources/image_picker_ios/FLTImagePickerPlugin.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ - (void)launchPHPickerWithContext:(nonnull FLTImagePickerMethodCallContext *)con
9999
PHPickerConfiguration *config =
100100
[[PHPickerConfiguration alloc] initWithPhotoLibrary:PHPhotoLibrary.sharedPhotoLibrary];
101101
config.selectionLimit = context.maxItemCount;
102+
config.preferredAssetRepresentationMode = PHPickerConfigurationAssetRepresentationModeCurrent;
102103
NSMutableArray<PHPickerFilter *> *filters = [[NSMutableArray alloc] init];
103104
if (context.includeImages) {
104105
[filters addObject:[PHPickerFilter imagesFilter]];

packages/image_picker/image_picker_ios/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: image_picker_ios
22
description: iOS implementation of the image_picker plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_ios
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
5-
version: 0.8.13+2
5+
version: 0.8.13+3
66

77
environment:
88
sdk: ^3.9.0

0 commit comments

Comments
 (0)