Skip to content

Replace deprecated kUTTypeGIF with UTTypeGIF in image utilities#10861

Closed
berlisB wants to merge 2 commits intoflutter:mainfrom
berlisB:fix/deprecated-kuttypegif
Closed

Replace deprecated kUTTypeGIF with UTTypeGIF in image utilities#10861
berlisB wants to merge 2 commits intoflutter:mainfrom
berlisB:fix/deprecated-kuttypegif

Conversation

@berlisB
Copy link

@berlisB berlisB commented Jan 23, 2026

No description provided.

@flutter-dashboard
Copy link

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.

@google-cla
Copy link

google-cla bot commented Jan 23, 2026

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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the code to use UTTypeGIF instead of the deprecated kUTTypeGIF. The review comments address issues with the current implementation, such as the need to use the identifier property of UTType objects and to import the UniformTypeIdentifiers framework. Suggestions also include adding @available checks to maintain backward compatibility. Per the repository's contributing guide, changes to native plugin code should be accompanied by tests. Please consider adding tests for this change.

NSMutableDictionary<NSString *, id> *options = [NSMutableDictionary dictionary];
options[(NSString *)kCGImageSourceShouldCache] = @YES;
options[(NSString *)kCGImageSourceTypeIdentifierHint] = (NSString *)kUTTypeGIF;
options[(NSString *)kCGImageSourceTypeIdentifierHint] = (NSString *)UTTypeGIF;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The direct usage of UTTypeGIF is incorrect. UTTypeGIF is a UTType object, and in Objective-C, you must use its identifier property to get the string representation. Casting a UTType* to NSString* is not the correct way to get the identifier and will lead to unexpected behavior.

Additionally, to use UTTypeGIF, you must import the UniformTypeIdentifiers framework by adding #import <UniformTypeIdentifiers/UniformTypeIdentifiers.h> at the top of the file. Without this import, the code will not compile.

To maintain compatibility with iOS versions older than 14, it's important to include an @available check to conditionally use the new API.

Suggested change
options[(NSString *)kCGImageSourceTypeIdentifierHint] = (NSString *)UTTypeGIF;
options[(NSString *)kCGImageSourceTypeIdentifierHint] = @available(iOS 14.0, *) ? UTTypeGIF.identifier : (NSString *)kUTTypeGIF;

Comment on lines 101 to 102
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(
(__bridge CFURLRef)[NSURL fileURLWithPath:path], kUTTypeGIF, gifInfo.images.count, NULL);
(__bridge CFURLRef)[NSURL fileURLWithPath:path], UTTypeGIF, gifInfo.images.count, NULL);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The usage of UTTypeGIF here is incorrect. CGImageDestinationCreateWithURL expects a CFStringRef for the type. UTTypeGIF is a UTType object. In Objective-C, you must use its identifier property and bridge it to CFStringRef.

Additionally, the UniformTypeIdentifiers framework needs to be imported via #import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>.

To ensure backward compatibility with iOS versions below 14, an @available check is necessary.

  CFStringRef type = kUTTypeGIF;
  if (@available(iOS 14.0, *)) {
    type = (__bridge CFStringRef)UTTypeGIF.identifier;
  }
  CGImageDestinationRef destination = CGImageDestinationCreateWithURL(
      (__bridge CFURLRef)[NSURL fileURLWithPath:path], type, gifInfo.images.count, NULL);

@stuartmorgan-g
Copy link
Collaborator

In the future, please follow the steps in the PR template instead of deleting them all.

Closing since there is already a PR for this issue that follows our process (#10848).

@berlisB
Copy link
Author

berlisB commented Jan 23, 2026

Thanks for handling this — I worked on a similar fix and learned a lot about UTType migration.

@berlisB berlisB deleted the fix/deprecated-kuttypegif branch January 23, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants