Replace deprecated kUTTypeGIF with UTTypeGIF in image utilities#10861
Replace deprecated kUTTypeGIF with UTTypeGIF in image utilities#10861berlisB wants to merge 2 commits intoflutter:mainfrom
Conversation
|
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 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; |
There was a problem hiding this comment.
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.
| options[(NSString *)kCGImageSourceTypeIdentifierHint] = (NSString *)UTTypeGIF; | |
| options[(NSString *)kCGImageSourceTypeIdentifierHint] = @available(iOS 14.0, *) ? UTTypeGIF.identifier : (NSString *)kUTTypeGIF; |
| CGImageDestinationRef destination = CGImageDestinationCreateWithURL( | ||
| (__bridge CFURLRef)[NSURL fileURLWithPath:path], kUTTypeGIF, gifInfo.images.count, NULL); | ||
| (__bridge CFURLRef)[NSURL fileURLWithPath:path], UTTypeGIF, gifInfo.images.count, NULL); |
There was a problem hiding this comment.
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);|
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). |
|
Thanks for handling this — I worked on a similar fix and learned a lot about UTType migration. |
No description provided.