From c81aec4ccda5d34fd729a59132e40f200e708406 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 8 Nov 2022 14:57:18 +0800 Subject: [PATCH] Ignore the dynamic UTI type hint to avoid extra log --- SDWebImage/Core/SDImageCacheDefine.m | 10 +++++++++- SDWebImage/Core/SDImageIOAnimatedCoder.m | 6 +++++- SDWebImage/Core/SDImageIOCoder.m | 6 +++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/SDWebImage/Core/SDImageCacheDefine.m b/SDWebImage/Core/SDImageCacheDefine.m index db3f43fa..0e9ec44b 100644 --- a/SDWebImage/Core/SDImageCacheDefine.m +++ b/SDWebImage/Core/SDImageCacheDefine.m @@ -35,6 +35,10 @@ SDImageCoderOptions * _Nonnull SDGetDecodeOptionsFromContext(SDWebImageContext * if (!typeIdentifierHint) { // UTI has high priority fileExtensionHint = cacheKey.pathExtension; // without dot + if (fileExtensionHint.length == 0) { + // Ignore file extension which is empty + fileExtensionHint = nil; + } } // First check if user provided decode options @@ -71,7 +75,11 @@ void SDSetDecodeOptionsToContext(SDWebImageMutableContext * _Nonnull mutableCont if (!typeIdentifierHint) { NSString *fileExtensionHint = decodeOptions[SDImageCoderDecodeFileExtensionHint]; if (fileExtensionHint) { - typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, NULL); + typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, kUTTypeImage); + // Ignore dynamic UTI + if (UTTypeIsDynamic((__bridge CFStringRef)typeIdentifierHint)) { + typeIdentifierHint = nil; + } } } mutableContext[SDWebImageContextImageTypeIdentifierHint] = typeIdentifierHint; diff --git a/SDWebImage/Core/SDImageIOAnimatedCoder.m b/SDWebImage/Core/SDImageIOAnimatedCoder.m index 56261eb3..072e4dbd 100644 --- a/SDWebImage/Core/SDImageIOAnimatedCoder.m +++ b/SDWebImage/Core/SDImageIOAnimatedCoder.m @@ -372,7 +372,11 @@ static CGImageRef __nullable SDCGImageCreateCopy(CGImageRef cg_nullable image) { // Check file extension and convert to UTI, from: https://stackoverflow.com/questions/1506251/getting-an-uniform-type-identifier-for-a-given-extension NSString *fileExtensionHint = options[SDImageCoderDecodeFileExtensionHint]; if (fileExtensionHint) { - typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, NULL); + typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, kUTTypeImage); + // Ignore dynamic UTI + if (UTTypeIsDynamic((__bridge CFStringRef)typeIdentifierHint)) { + typeIdentifierHint = nil; + } } } else if ([typeIdentifierHint isEqual:NSNull.null]) { // Hack if user don't want to imply file extension diff --git a/SDWebImage/Core/SDImageIOCoder.m b/SDWebImage/Core/SDImageIOCoder.m index 39bff408..489a2d18 100644 --- a/SDWebImage/Core/SDImageIOCoder.m +++ b/SDWebImage/Core/SDImageIOCoder.m @@ -124,7 +124,11 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination // Check file extension and convert to UTI, from: https://stackoverflow.com/questions/1506251/getting-an-uniform-type-identifier-for-a-given-extension NSString *fileExtensionHint = options[SDImageCoderDecodeFileExtensionHint]; if (fileExtensionHint) { - typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, NULL); + typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, kUTTypeImage); + // Ignore dynamic UTI + if (UTTypeIsDynamic((__bridge CFStringRef)typeIdentifierHint)) { + typeIdentifierHint = nil; + } } } else if ([typeIdentifierHint isEqual:NSNull.null]) { // Hack if user don't want to imply file extension