Skip to content

Commit 44a58ab

Browse files
authored
[image_picker_ios] Fix deprecated kUTTypeGIF usage (#10848)
[image_picker_ios] Fix deprecated kUTTypeGIF usage This PR replaces the deprecated `kUTTypeGIF` constant with the modern `UTTypeGIF` API to fix iOS 15+ deprecation warnings in the image_picker_ios plugin. **Changes:** - Added `UniformTypeIdentifiers` framework import to affected files - Replaced `kUTTypeGIF` with `UTTypeGIF.identifier` for iOS 14+ - Added `@available(iOS 14.0, *)` checks to maintain backward compatibility with iOS 13 The minimum iOS deployment target is 13.0, so the code uses conditional compilation to support both the new API (iOS 14+) and the deprecated API (iOS 13) where necessary. **Files changed:** - `FLTImagePickerImageUtil.m` - Updated GIF image source type hint - `FLTImagePickerPhotoAssetUtil.m` - Updated GIF destination type Fixes flutter/flutter#181291 ## 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 93a583f commit 44a58ab

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎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+6
2+
3+
* Replaces deprecated `kUTTypeGIF` with `UTTypeGIF` to fix iOS 15+ deprecation warnings.
4+
15
## 0.8.13+5
26

37
* Fixes camera confirmation buttons (e.g., Retake/Use Photo) taps passing through to the underlying Flutter UI while the picker is dismissing on some iOS versions (e.g., iOS 26).

‎packages/image_picker/image_picker_ios/ios/image_picker_ios/Sources/image_picker_ios/FLTImagePickerImageUtil.m‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#import "FLTImagePickerImageUtil.h"
66
#import <MobileCoreServices/MobileCoreServices.h>
7+
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
78

89
@interface GIFInfo ()
910

@@ -117,7 +118,13 @@ + (GIFInfo *)scaledGIFImage:(NSData *)data
117118
maxHeight:(NSNumber *)maxHeight {
118119
NSMutableDictionary<NSString *, id> *options = [NSMutableDictionary dictionary];
119120
options[(NSString *)kCGImageSourceShouldCache] = @YES;
120-
options[(NSString *)kCGImageSourceTypeIdentifierHint] = (NSString *)kUTTypeGIF;
121+
NSString *gifTypeIdentifier;
122+
if (@available(iOS 14.0, *)) {
123+
gifTypeIdentifier = UTTypeGIF.identifier;
124+
} else {
125+
gifTypeIdentifier = (NSString *)kUTTypeGIF;
126+
}
127+
options[(NSString *)kCGImageSourceTypeIdentifierHint] = gifTypeIdentifier;
121128

122129
CGImageSourceRef imageSource =
123130
CGImageSourceCreateWithData((__bridge CFDataRef)data, (__bridge CFDictionaryRef)options);

‎packages/image_picker/image_picker_ios/ios/image_picker_ios/Sources/image_picker_ios/FLTImagePickerPhotoAssetUtil.m‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#import "FLTImagePickerMetaDataUtil.h"
88

99
#import <MobileCoreServices/MobileCoreServices.h>
10+
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
1011

1112
@implementation FLTImagePickerPhotoAssetUtil
1213

@@ -98,8 +99,14 @@ + (NSString *)saveImageWithMetaData:(NSDictionary *)metaData
9899
+ (NSString *)saveImageWithMetaData:(NSDictionary *)metaData
99100
gifInfo:(GIFInfo *)gifInfo
100101
path:(NSString *)path {
102+
CFStringRef imageType;
103+
if (@available(iOS 14.0, *)) {
104+
imageType = (__bridge CFStringRef)UTTypeGIF.identifier;
105+
} else {
106+
imageType = kUTTypeGIF;
107+
}
101108
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(
102-
(__bridge CFURLRef)[NSURL fileURLWithPath:path], kUTTypeGIF, gifInfo.images.count, NULL);
109+
(__bridge CFURLRef)[NSURL fileURLWithPath:path], imageType, gifInfo.images.count, NULL);
103110

104111
NSDictionary *frameProperties = @{
105112
(__bridge NSString *)kCGImagePropertyGIFDictionary : @{

‎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+5
5+
version: 0.8.13+6
66

77
environment:
88
sdk: ^3.10.0

0 commit comments

Comments
 (0)