[image_picker_ios] Replace deprecated kUTTypeImage/kUTTypeMovie with UTType API - #12778
[image_picker_ios] Replace deprecated kUTTypeImage/kUTTypeMovie with UTType API#12778ledexsoft wants to merge 2 commits into
Conversation
…UTType on iOS 14+
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request replaces the deprecated kUTTypeImage and kUTTypeMovie with UTTypeImage and UTTypeMovie on iOS 14.0+ to resolve deprecation warnings, importing the UniformTypeIdentifiers framework. Feedback suggests simplifying the conditional initialization of the media type variables by setting the fallback values as defaults, which eliminates the need for the else blocks.
| if (context.includeImages) { | ||
| [mediaTypes addObject:(NSString *)kUTTypeImage]; | ||
| NSString *imageType; | ||
| if (@available(iOS 14.0, *)) { | ||
| imageType = UTTypeImage.identifier; | ||
| } else { | ||
| imageType = (NSString *)kUTTypeImage; | ||
| } | ||
| [mediaTypes addObject:imageType]; | ||
| } | ||
| if (context.includeVideo) { | ||
| [mediaTypes addObject:(NSString *)kUTTypeMovie]; | ||
| NSString *movieType; | ||
| if (@available(iOS 14.0, *)) { | ||
| movieType = UTTypeMovie.identifier; | ||
| } else { | ||
| movieType = (NSString *)kUTTypeMovie; | ||
| } | ||
| [mediaTypes addObject:movieType]; | ||
| imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh; | ||
| } |
There was a problem hiding this comment.
This code can be simplified by initializing the type variables with their fallback values directly, avoiding the need for the else blocks and making the code more concise and readable.
if (context.includeImages) {
NSString *imageType = (NSString *)kUTTypeImage;
if (@available(iOS 14.0, *)) {
imageType = UTTypeImage.identifier;
}
[mediaTypes addObject:imageType];
}
if (context.includeVideo) {
NSString *movieType = (NSString *)kUTTypeMovie;
if (@available(iOS 14.0, *)) {
movieType = UTTypeMovie.identifier;
}
[mediaTypes addObject:movieType];
imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
}There was a problem hiding this comment.
Applied — the legacy kUTType constants are now the default value and the modern UTType overrides them on iOS 14+, which removes the else branches. Pushed in 9df0432.
Fixes iOS deprecation warnings surfaced when building with Flutter 3.44.8 / Xcode 26 (iOS 26 SDK):
(
FLTImagePickerPlugin.m:130,133)Cause
launchUIImagePickerWithSource:still addskUTTypeImage/kUTTypeMoviedirectly toUIImagePickerController.mediaTypes. The legacykUTType*constants were deprecated in iOS 15 in favor of the modernUTTypeAPI.Fix
Replaces the deprecated constants with
UTTypeImage.identifier/UTTypeMovie.identifierguarded by@available(iOS 14.0, *), keeping the legacy constants as the fallback for iOS 13 (the pod deployment target is 13.0). This mirrors the pattern already merged upstream in #10848 for the same plugin'skUTTypeGIFusages inFLTImagePickerImageUtil.mandFLTImagePickerPhotoAssetUtil.m, which appear to have missed these two call sites inFLTImagePickerPlugin.m.Verification
clang -fsyntax-only -fobjc-arcagainst the iOS 26 simulator SDK (deployment target 13.0) passes.Detected with Flutter 3.44.8 / Xcode 26 (iOS 26 SDK).