Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#import "FLTImagePickerImageUtil.h"
#import <MobileCoreServices/MobileCoreServices.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>


@interface GIFInfo ()

Expand Down Expand Up @@ -117,7 +119,14 @@ + (GIFInfo *)scaledGIFImage:(NSData *)data
maxHeight:(NSNumber *)maxHeight {
NSMutableDictionary<NSString *, id> *options = [NSMutableDictionary dictionary];
options[(NSString *)kCGImageSourceShouldCache] = @YES;
options[(NSString *)kCGImageSourceTypeIdentifierHint] = (NSString *)kUTTypeGIF;
if (@available(iOS 15.0, *)) {
options[(NSString *)kCGImageSourceTypeIdentifierHint] =
(NSString *)UTTypeGIF.identifier;
} else {
options[(NSString *)kCGImageSourceTypeIdentifierHint] =
(NSString *)kUTTypeGIF;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While this correctly fixes the deprecation warning on iOS 15, the UniformTypeIdentifiers API is available starting from iOS 14. It's better to adopt the new API from iOS 14 onwards. Also, the cast (NSString *) on UTTypeGIF.identifier is redundant as it already returns an NSString *. Finally, the indentation in this block is inconsistent and an extra blank line has been added, both of which should be fixed to improve readability.

  if (@available(iOS 14.0, *)) {
    options[(NSString *)kCGImageSourceTypeIdentifierHint] = UTTypeGIF.identifier;
  } else {
    options[(NSString *)kCGImageSourceTypeIdentifierHint] = (NSString *)kUTTypeGIF;
  }
References
  1. Code should follow the relevant style guides and use the correct auto-formatter for each language. The indentation in the added code block is inconsistent and an extra blank line was added. (link)


CGImageSourceRef imageSource =
CGImageSourceCreateWithData((__bridge CFDataRef)data, (__bridge CFDictionaryRef)options);
Expand Down