-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hulk
committed
Jun 1, 2023
1 parent
92ba3ca
commit c4e57af
Showing
7 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
iOS/DiDiPrism/Src/Core/Intercept/SDImageCache+PrismIntercept.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// SDImageCache+PrismIntercept.h | ||
// DiDiPrism | ||
// | ||
// Created by hulk on 2023/6/1. | ||
// | ||
|
||
#if __has_include(<SDWebImage/SDImageCache.h>) | ||
|
||
#import <SDWebImage/SDImageCache.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface SDImageCache (PrismIntercept) | ||
+ (void)prism_swizzleMethodIMP; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif |
57 changes: 57 additions & 0 deletions
57
iOS/DiDiPrism/Src/Core/Intercept/SDImageCache+PrismIntercept.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// SDImageCache+PrismIntercept.m | ||
// DiDiPrism | ||
// | ||
// Created by hulk on 2023/6/1. | ||
// | ||
|
||
#if __has_include(<SDWebImage/SDImageCache.h>) | ||
|
||
#import "SDImageCache+PrismIntercept.h" | ||
#import "PrismRuntimeUtil.h" | ||
#import "UIImage+PrismIntercept.h" | ||
|
||
@implementation SDImageCache (PrismIntercept) | ||
#pragma mark - public method | ||
+ (void)prism_swizzleMethodIMP { | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
[PrismRuntimeUtil hookClass:[self class] originalSelector:@selector(storeImage:imageData:forKey:toMemory:toDisk:completion:) swizzledSelector:@selector(prism_autoDot_storeImage:imageData:forKey:toMemory:toDisk:completion:)]; | ||
[PrismRuntimeUtil hookClass:[self class] originalSelector:@selector(imageFromMemoryCacheForKey:) swizzledSelector:@selector(prism_autoDot_imageFromMemoryCacheForKey:)]; | ||
[PrismRuntimeUtil hookClass:[self class] originalSelector:@selector(diskImageForKey:data:options:context:) swizzledSelector:@selector(prism_autoDot_diskImageForKey:data:options:context:)]; | ||
|
||
}); | ||
} | ||
|
||
#pragma mark - private method | ||
- (void)prism_autoDot_storeImage:(nullable UIImage *)image | ||
imageData:(nullable NSData *)imageData | ||
forKey:(nullable NSString *)key | ||
toMemory:(BOOL)toMemory | ||
toDisk:(BOOL)toDisk | ||
completion:(nullable SDWebImageNoParamsBlock)completionBlock { | ||
if (image && [image isKindOfClass:[UIImage class]] && key) { | ||
image.prismAutoDotImageUrl = key; | ||
} | ||
|
||
[self prism_autoDot_storeImage:image imageData:imageData forKey:key toMemory:toMemory toDisk:toDisk completion:completionBlock]; | ||
} | ||
|
||
- (nullable UIImage *)prism_autoDot_imageFromMemoryCacheForKey:(nullable NSString *)key { | ||
UIImage *image = [self prism_autoDot_imageFromMemoryCacheForKey:key]; | ||
if (image && [image isKindOfClass:[UIImage class]] && key) { | ||
image.prismAutoDotImageUrl = key; | ||
} | ||
return image; | ||
} | ||
|
||
- (nullable UIImage *)prism_autoDot_diskImageForKey:(nullable NSString *)key data:(nullable NSData *)data options:(SDImageCacheOptions)options context:(SDWebImageContext *)context { | ||
UIImage *image = [self prism_autoDot_diskImageForKey:key data:data options:options context:context]; | ||
if (image && [image isKindOfClass:[UIImage class]] && key) { | ||
image.prismAutoDotImageUrl = key; | ||
} | ||
return image; | ||
} | ||
@end | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters