Migrate MIME-type lookup to UTType (UniformTypeIdentifiers)
Replace the deprecated CoreServices UTI calls (UTTypeCreatePreferredIdentifierForTag / UTTypeCopyPreferredTagWithClass) in GCDWebServerGetMimeTypeForExtension with the modern [UTType typeWithFilenameExtension:].preferredMIMEType, removing the -Wdeprecated-declarations pragma. Behavior is unchanged: known extensions map to the same MIME type, unknown ones fall back to the default. The UniformTypeIdentifiers framework (macOS 11+ / iOS 14+ / tvOS 14+, within the project's deployment targets) is now linked in all three build systems: Xcode (OTHER_LDFLAGS), CocoaPods (Core subspec frameworks), and SwiftPM (linkedFramework). Verified: Run-Tests.sh, swift build, and pod lib lint all pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -35,6 +35,7 @@
|
||||
#else
|
||||
#import <SystemConfiguration/SystemConfiguration.h>
|
||||
#endif
|
||||
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
#import <ifaddrs.h>
|
||||
@ -176,17 +177,7 @@ NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension, NSDictionary<
|
||||
mimeType = [builtInOverrides objectForKey:extension];
|
||||
}
|
||||
if (mimeType == nil) {
|
||||
// These CoreServices UTI functions are deprecated since macOS 12 / iOS 15 in favor of the
|
||||
// UniformTypeIdentifiers UTType class, but they still work and avoid pulling in a new framework
|
||||
// dependency across the Xcode/CocoaPods/SPM builds. Silence the deprecation under -Werror.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, NULL);
|
||||
if (uti) {
|
||||
mimeType = CFBridgingRelease(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType));
|
||||
CFRelease(uti);
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
mimeType = [UTType typeWithFilenameExtension:extension].preferredMIMEType;
|
||||
}
|
||||
}
|
||||
return mimeType ? mimeType : kGCDWebServerDefaultMimeType;
|
||||
|
||||
Reference in New Issue
Block a user