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:
@ -44,7 +44,7 @@ This script was originally written for Xcode 11.3 and was updated for current Xc
|
||||
- The `webUploader` fixture test is **commented out**: this fork customized `GCDWebUploader` (delete/move/create disabled in commit `ef4b622`), so the recorded `Tests/WebUploader` fixtures no longer match. Re-record them or re-enable the line if those features are restored.
|
||||
- The **tvOS build step is commented out** because it requires the tvOS Simulator runtime to be installed (`xcodebuild -downloadPlatform tvOS`); without it the storyboard compile fails with "tvOS … Platform Not Installed". Re-enable once the runtime is present.
|
||||
|
||||
Two project/source adjustments were also needed for the suite to build under current Xcode: the `Tests (Mac)` target sets `GENERATE_INFOPLIST_FILE = YES`, and the deprecated CoreServices UTI calls in `GCDWebServerFunctions.m` are wrapped in a `-Wdeprecated-declarations` pragma (the project builds Release with `-Werror`).
|
||||
A project adjustment was also needed for the suite to build under current Xcode: the `Tests (Mac)` target sets `GENERATE_INFOPLIST_FILE = YES`. MIME-type lookup in `GCDWebServerFunctions.m` uses the modern `UTType` API (UniformTypeIdentifiers), so that framework is linked in all three build systems (Xcode `OTHER_LDFLAGS`, the podspec Core subspec, and `Package.swift`).
|
||||
|
||||
### How the fixture-replay tests work
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ Pod::Spec.new do |s|
|
||||
s.subspec 'Core' do |cs|
|
||||
cs.source_files = 'GCDWebServer/**/*.{h,m}'
|
||||
cs.private_header_files = "GCDWebServer/Core/GCDWebServerPrivate.h"
|
||||
cs.frameworks = 'UniformTypeIdentifiers'
|
||||
cs.ios.library = 'z'
|
||||
cs.ios.frameworks = 'CoreServices', 'CFNetwork'
|
||||
cs.tvos.library = 'z'
|
||||
|
||||
@ -1169,6 +1169,7 @@
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
BUNDLE_VERSION_STRING = 3.5.4;
|
||||
OTHER_LDFLAGS = "-framework UniformTypeIdentifiers";
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
@ -1239,6 +1240,7 @@
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
BUNDLE_VERSION_STRING = 3.5.4;
|
||||
OTHER_LDFLAGS = "-framework UniformTypeIdentifiers";
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -27,6 +27,7 @@ let package = Package(
|
||||
],
|
||||
linkerSettings: [
|
||||
.linkedLibrary("z"),
|
||||
.linkedFramework("UniformTypeIdentifiers"),
|
||||
.linkedFramework("CoreServices", .when(platforms: [.iOS, .tvOS])),
|
||||
.linkedFramework("CFNetwork", .when(platforms: [.iOS, .tvOS])),
|
||||
.linkedFramework("SystemConfiguration", .when(platforms: [.macOS])),
|
||||
|
||||
Reference in New Issue
Block a user