Merge pull request #2808 from dreampiggy/project_uikit_macos

Feature: Support UIKit for macOS (Catalyst)
This commit is contained in:
DreamPiggy 2019-08-19 14:55:03 +08:00 committed by GitHub
commit 8898909f1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 27 deletions

View File

@ -1,6 +1,6 @@
language: objective-c
osx_image: xcode10.2
osx_image: xcode10.3
env:
global:
@ -40,20 +40,22 @@ script:
- rm -rf ~/.build
- echo Build as static library
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage static' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage static' -sdk watchsimulator -configuration Debug | xcpretty -c
- xcodebuild build -project SDWebImage.xcodeproj -scheme 'SDWebImage static' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
- xcodebuild build -project SDWebImage.xcodeproj -scheme 'SDWebImage static' -sdk watchsimulator -configuration Debug | xcpretty -c
- echo Clean DerivedData
- rm -rf ~/Library/Developer/Xcode/DerivedData/
- echo Build as dynamic frameworks
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk macosx -configuration Debug | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk appletvsimulator -configuration Debug | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk watchsimulator -configuration Debug | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImageMapKit' -sdk macosx -configuration Debug | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImageMapKit' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImageMapKit' -sdk appletvsimulator -configuration Debug | xcpretty -c
- xcodebuild build -project SDWebImage.xcodeproj -scheme 'SDWebImage' -sdk macosx -configuration Debug | xcpretty -c
- xcodebuild build -project SDWebImage.xcodeproj -scheme 'SDWebImage' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
- xcodebuild build -project SDWebImage.xcodeproj -scheme 'SDWebImage' -sdk appletvsimulator -configuration Debug | xcpretty -c
- xcodebuild build -project SDWebImage.xcodeproj -scheme 'SDWebImage' -sdk watchsimulator -configuration Debug | xcpretty -c
# - xcodebuild archive -project SDWebImage.xcodeproj -scheme 'SDWebImage' -destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' -configuration Debug | xcpretty -c
- xcodebuild build -project SDWebImage.xcodeproj -scheme 'SDWebImageMapKit' -sdk macosx -configuration Debug | xcpretty -c
- xcodebuild build -project SDWebImage.xcodeproj -scheme 'SDWebImageMapKit' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
- xcodebuild build -project SDWebImage.xcodeproj -scheme 'SDWebImageMapKit' -sdk appletvsimulator -configuration Debug | xcpretty -c
# - xcodebuild archive -project SDWebImage.xcodeproj -scheme 'SDWebImageMapKit' -destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' -configuration Debug | xcpretty -c
- echo Clean DerivedData
- rm -rf ~/Library/Developer/Xcode/DerivedData/
@ -64,6 +66,7 @@ script:
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage iOS Demo' -destination 'platform=iOS Simulator,name=iPhone XS' -configuration Debug CODE_SIGNING_ALLOWED=NO | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage TV Demo' -destination 'platform=tvOS Simulator,name=Apple TV 4K' -configuration Debug CODE_SIGNING_ALLOWED=NO | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage Watch Demo' -destination 'platform=iOS Simulator,name=iPhone XS' -configuration Debug CODE_SIGNING_ALLOWED=NO | xcpretty -c
# - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage iOS Demo' -destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' -configuration Debug CODE_SIGNING_ALLOWED=NO | xcpretty -c
- echo Clean DerivedData
- rm -rf ~/Library/Developer/Xcode/DerivedData/

View File

@ -223,3 +223,9 @@ VERSIONING_SYSTEM = apple-generic
// Code will load on this and later versions of watchOS. Framework APIs that are unavailable in earlier versions will be weak-linked; your code should check for null function pointers or specific system versions before calling newer APIs.
WATCHOS_DEPLOYMENT_TARGET = 2.0
// macOS Catalyst support
SUPPORTS_MACCATALYST = YES
// macOS Catalyst support
DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = NO

View File

@ -27,7 +27,7 @@
43A62A061D0E07600089D7DD /* ExtensionDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A62A051D0E07600089D7DD /* ExtensionDelegate.m */; };
43A62A091D0E07600089D7DD /* NotificationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A62A081D0E07600089D7DD /* NotificationController.m */; };
43A62A0B1D0E07600089D7DD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 43A62A0A1D0E07600089D7DD /* Assets.xcassets */; };
43A62A0F1D0E07600089D7DD /* SDWebImage Watch Demo.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 43A629EE1D0E07600089D7DD /* SDWebImage Watch Demo.app */; };
43A62A0F1D0E07600089D7DD /* SDWebImage Watch Demo.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 43A629EE1D0E07600089D7DD /* SDWebImage Watch Demo.app */; platformFilter = ios; };
531041C1157EAC8F00BBABC3 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537612E6155ABA44005750A4 /* ImageIO.framework */; };
5376129A155AB74D005750A4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53761299155AB74D005750A4 /* UIKit.framework */; };
5376129C155AB74D005750A4 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5376129B155AB74D005750A4 /* Foundation.framework */; };
@ -842,6 +842,7 @@
};
43A62A0E1D0E07600089D7DD /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
platformFilter = ios;
target = 43A629ED1D0E07600089D7DD /* SDWebImage Watch Demo */;
targetProxy = 43A62A0D1D0E07600089D7DD /* PBXContainerItemProxy */;
};
@ -925,7 +926,10 @@
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = "SDWebImage OSX Demo/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
SDKROOT = "";
SUPPORTED_PLATFORMS = macosx;
TARGETED_DEVICE_FAMILY = "";
@ -938,7 +942,10 @@
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = "SDWebImage OSX Demo/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
SDKROOT = "";
SUPPORTED_PLATFORMS = macosx;
TARGETED_DEVICE_FAMILY = "";
@ -951,7 +958,11 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = "";
INFOPLIST_FILE = "SDWebImage Watch Demo Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.dailymotion.SDWebImage-iOS-Demo.watchkitapp.watchkitextension";
SDKROOT = watchos;
SUPPORTED_PLATFORMS = "watchsimulator watchos";
@ -965,7 +976,11 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = "";
INFOPLIST_FILE = "SDWebImage Watch Demo Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.dailymotion.SDWebImage-iOS-Demo.watchkitapp.watchkitextension";
SDKROOT = watchos;
SUPPORTED_PLATFORMS = "watchsimulator watchos";

View File

@ -26,6 +26,11 @@ Pod::Spec.new do |s|
s.default_subspec = 'Core'
s.pod_target_xcconfig = {
'SUPPORTS_MACCATALYST' => 'YES',
'DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER' => 'NO'
}
s.subspec 'Core' do |core|
core.source_files = 'SDWebImage/Core/*.{h,m}', 'WebImage/SDWebImage.h', 'SDWebImage/Private/*.{h,m}'
core.exclude_files = 'SDWebImage/MapKit/*.{h,m}'

View File

@ -989,10 +989,11 @@
"$(SRCROOT)/build/appletvsimulator/SDWebImage.framework",
"$(SRCROOT)/build/watchos/SDWebImage.framework",
"$(SRCROOT)/build/watchsimulator/SDWebImage.framework",
"$(SRCROOT)/build/maccatalyst/SDWebImage.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "mkdir -p $(SRCROOT)/build\ndeclare -a PLATFORMS=(\"iphoneos\" \"iphonesimulator\" \"macosx\" \"appletvos\" \"appletvsimulator\" \"watchos\" \"watchsimulator\")\nfor CURRENT_PLATFORM in \"${PLATFORMS[@]}\"\ndo\nCONFIGURATION=\"Release\"\nif [[ $CURRENT_PLATFORM == *\"simulator\" ]]; then\nCONFIGURATION=\"Debug\"\nfi\nxcodebuild -sdk \"${CURRENT_PLATFORM}\" -scheme SDWebImage -configuration $CONFIGURATION CONFIGURATION_BUILD_DIR=\"${SRCROOT}/build/${CURRENT_PLATFORM}/\" SKIP_INSTALL=NO\ndone\n";
shellScript = "XCODE_VERSION=$(xcodebuild -version | head -n 1| awk -F ' ' '{print $2}')\nXCODE_VERSION_MAJOR=$(echo $XCODE_VERSION | awk -F '.' '{print $1}')\n\nmkdir -p $(SRCROOT)/build\ndeclare -a PLATFORMS=(\"iphoneos\" \"iphonesimulator\" \"macosx\" \"appletvos\" \"appletvsimulator\" \"watchos\" \"watchsimulator\" \"maccatalyst\")\nfor CURRENT_PLATFORM in \"${PLATFORMS[@]}\"\ndo\n if [[ $CURRENT_PLATFORM == *\"simulator\" ]]; then\n xcodebuild build -project \"SDWebImage.xcodeproj\" -sdk \"${CURRENT_PLATFORM}\" -scheme \"SDWebImage\" -configuration \"Debug\" -derivedDataPath \"${SRCROOT}/build/DerivedData\" CONFIGURATION_BUILD_DIR=\"${SRCROOT}/build/${CURRENT_PLATFORM}/\"\n else\n # macOS Catalyst\n if [[ $CURRENT_PLATFORM == \"maccatalyst\" ]]; then\n if [[ $XCODE_VERSION_MAJOR -lt 11 ]]; then\n # Xcode 10 does not support macOS Catalyst\n continue\n else\n xcodebuild archive -project \"SDWebImage.xcodeproj\" -scheme \"SDWebImage\" -configuration \"Release\" -destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' -archivePath \"${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive\" -derivedDataPath \"${SRCROOT}/build/DerivedData\" SKIP_INSTALL=NO\n fi\n else\n xcodebuild archive -project \"SDWebImage.xcodeproj\" -sdk \"${CURRENT_PLATFORM}\" -scheme \"SDWebImage\" -configuration \"Release\" -archivePath \"${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive\" SKIP_INSTALL=NO\n fi\n mv \"${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive/Products/Library/Frameworks/SDWebImage.framework\" \"${SRCROOT}/build/${CURRENT_PLATFORM}/\"\n mv \"${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive/dSYMs/SDWebImage.framework.dSYM\" \"${SRCROOT}/build/${CURRENT_PLATFORM}/\"\n rm -rf \"${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive/\"\n fi\ndone\n";
};
326CA51422BA25F70033A92F /* Create XCFramework */ = {
isa = PBXShellScriptBuildPhase;
@ -1009,6 +1010,7 @@
"$(SRCROOT)/build/appletvsimulator/SDWebImage.framework",
"$(SRCROOT)/build/watchos/SDWebImage.framework",
"$(SRCROOT)/build/watchsimulator/SDWebImage.framework",
"$(SRCROOT)/build/maccatalyst/SDWebImage.framework",
);
name = "Create XCFramework";
outputFileListPaths = (
@ -1018,7 +1020,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "XCODE_VERSION=$(xcodebuild -version | head -n 1| awk -F ' ' '{print $2}')\nXCODE_VERSION_MAJOR=$(echo $XCODE_VERSION | awk -F '.' '{print $1}')\nif [ $XCODE_VERSION_MAJOR -lt 11 ]\nthen\necho \"Xcode 10 does not support xcframework. You can still use the individual framework for each platform.\"\nopen -a Finder \"${SRCROOT}/build/\"\nexit 0\nfi\ndeclare -a PLATFORMS=(\"iphoneos\" \"iphonesimulator\" \"macosx\" \"appletvos\" \"appletvsimulator\" \"watchos\" \"watchsimulator\")\nCOMMAND_ARGS=\"\"\nfor CURRENT_PLATFORM in \"${PLATFORMS[@]}\"\ndo\nCOMMAND_ARGS=\"${COMMAND_ARGS} -framework ${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.framework\"\ndone\nxcodebuild -create-xcframework $COMMAND_ARGS -output \"${SRCROOT}/build/SDWebImage.xcframework\"\nopen -a Finder \"${SRCROOT}/build/SDWebImage.xcframework\"\n";
shellScript = "XCODE_VERSION=$(xcodebuild -version | head -n 1| awk -F ' ' '{print $2}')\nXCODE_VERSION_MAJOR=$(echo $XCODE_VERSION | awk -F '.' '{print $1}')\n\nif [ $XCODE_VERSION_MAJOR -lt 11 ]\nthen\n echo \"Xcode 10 does not support xcframework. You can still use the individual framework for each platform.\"\n open -a Finder \"${SRCROOT}/build/\"\n exit 0\nfi\n\ndeclare -a PLATFORMS=(\"iphoneos\" \"iphonesimulator\" \"macosx\" \"appletvos\" \"appletvsimulator\" \"watchos\" \"watchsimulator\" \"maccatalyst\")\nCOMMAND_ARGS=\"\"\nfor CURRENT_PLATFORM in \"${PLATFORMS[@]}\"\ndo\n COMMAND_ARGS=\"${COMMAND_ARGS} -framework ${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.framework\"\ndone\n\n# Combine XCFramework\nxcodebuild -create-xcframework $COMMAND_ARGS -output \"${SRCROOT}/build/SDWebImage.xcframework\"\nopen -a Finder \"${SRCROOT}/build/SDWebImage.xcframework\"\n";
};
/* End PBXShellScriptBuildPhase section */

View File

@ -1,9 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:SDWebImage.xcodeproj">
</FileRef>
<FileRef
location = "group:Examples/SDWebImage Demo.xcodeproj">
</FileRef>

View File

@ -203,7 +203,7 @@ static NSUInteger SDDeviceFreeMemory() {
// We need call super method to keep function. This will impliedly call `setNeedsDisplay`. But we have no way to avoid this when using animated image. So we call `setNeedsDisplay` again at the end.
super.image = image;
if ([image conformsToProtocol:@protocol(SDAnimatedImage)]) {
if ([image.class conformsToProtocol:@protocol(SDAnimatedImage)]) {
NSUInteger animatedImageFrameCount = ((UIImage<SDAnimatedImage> *)image).animatedImageFrameCount;
// Check the frame count
if (animatedImageFrameCount <= 1) {
@ -536,9 +536,11 @@ static NSUInteger SDDeviceFreeMemory() {
// Early return
return;
}
if ([image conformsToProtocol:@protocol(SDAnimatedImage)] && image.sd_isIncremental) {
// We must use `image.class conformsToProtocol:` instead of `image conformsToProtocol:` here
// Because UIKit on macOS, using internal hard-coded override method, which returns NO
if ([image.class conformsToProtocol:@protocol(SDAnimatedImage)] && image.sd_isIncremental) {
UIImage *previousImage = self.image;
if ([previousImage conformsToProtocol:@protocol(SDAnimatedImage)] && previousImage.sd_isIncremental) {
if ([previousImage.class conformsToProtocol:@protocol(SDAnimatedImage)] && previousImage.sd_isIncremental) {
NSData *previousData = [((UIImage<SDAnimatedImage> *)previousImage) animatedImageData];
NSData *currentData = [((UIImage<SDAnimatedImage> *)image) animatedImageData];
// Check whether to use progressive rendering or not

View File

@ -47,7 +47,7 @@ UIImage * _Nullable SDImageCacheDecodeImageData(NSData * _Nonnull imageData, NSS
}
if (image) {
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;
if ([image conformsToProtocol:@protocol(SDAnimatedImage)]) {
if ([image.class conformsToProtocol:@protocol(SDAnimatedImage)]) {
// `SDAnimatedImage` do not decode
shouldDecode = NO;
} else if (image.sd_isAnimated) {

View File

@ -61,7 +61,7 @@ UIImage * _Nullable SDImageLoaderDecodeImageData(NSData * _Nonnull imageData, NS
}
if (image) {
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;
if ([image conformsToProtocol:@protocol(SDAnimatedImage)]) {
if ([image.class conformsToProtocol:@protocol(SDAnimatedImage)]) {
// `SDAnimatedImage` do not decode
shouldDecode = NO;
} else if (image.sd_isAnimated) {
@ -143,7 +143,7 @@ UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NSData * _Nonnull im
}
if (image) {
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;
if ([image conformsToProtocol:@protocol(SDAnimatedImage)]) {
if ([image.class conformsToProtocol:@protocol(SDAnimatedImage)]) {
// `SDAnimatedImage` do not decode
shouldDecode = NO;
} else if (image.sd_isAnimated) {

View File

@ -151,9 +151,13 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
imageView.image = image;
#if SD_MAC
expect(imageView.wantsUpdateLayer).beTruthy();
#else
#if TARGET_OS_MACCATALYST
// macOS's UIImageView seems does not setup layer.contents until render on screen
#else
expect(imageView.layer.contents).notTo.beNil();
#endif
#endif
}
- (void)test13AnimatedImageViewInitWithImage {
@ -264,7 +268,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
// Progressive image may be nil when download data is not enough
if (image) {
expect(image.sd_isIncremental).beTruthy();
expect([image conformsToProtocol:@protocol(SDAnimatedImage)]).beTruthy();
expect([image.class conformsToProtocol:@protocol(SDAnimatedImage)]).beTruthy();
BOOL isProgressive = imageView.isProgressive;
expect(isProgressive).equal(YES);
}