Skip to content

Commit c315c30

Browse files
committed
Support to cache the LPLinkMetadata's title into the disk cache, make it possible for UI display
1 parent 29aef9e commit c315c30

5 files changed

Lines changed: 24 additions & 7 deletions

File tree

Example/Podfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use_frameworks!
33
target 'SDWebImageLinkPlugin_Example' do
44
platform :ios, '13.0'
55
pod 'SDWebImageLinkPlugin', :path => '../'
6+
pod 'SDWebImage', :path => '/Users/lizhuoli/Documents/GitHub/sdwebImage'
67

78
target 'SDWebImageLinkPlugin_Tests' do
89
inherit! :search_paths
@@ -13,4 +14,5 @@ end
1314
target 'SDWebImageLinkPlugin_Example macOS' do
1415
platform :osx, '10.15'
1516
pod 'SDWebImageLinkPlugin', :path => '../'
17+
pod 'SDWebImage', :path => '/Users/lizhuoli/Documents/GitHub/sdwebImage'
1618
end

Example/Podfile.lock

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
PODS:
22
- Expecta (1.0.6)
3-
- SDWebImage (5.3.1):
4-
- SDWebImage/Core (= 5.3.1)
5-
- SDWebImage/Core (5.3.1)
3+
- SDWebImage (5.3.2):
4+
- SDWebImage/Core (= 5.3.2)
5+
- SDWebImage/Core (5.3.2)
66
- SDWebImageLinkPlugin (0.1.0):
77
- SDWebImage (~> 5.0)
88

99
DEPENDENCIES:
1010
- Expecta
11+
- SDWebImage (from `/Users/lizhuoli/Documents/GitHub/sdwebImage`)
1112
- SDWebImageLinkPlugin (from `../`)
1213

1314
SPEC REPOS:
1415
trunk:
1516
- Expecta
16-
- SDWebImage
1717

1818
EXTERNAL SOURCES:
19+
SDWebImage:
20+
:path: "/Users/lizhuoli/Documents/GitHub/sdwebImage"
1921
SDWebImageLinkPlugin:
2022
:path: "../"
2123

2224
SPEC CHECKSUMS:
2325
Expecta: 3b6bd90a64b9a1dcb0b70aa0e10a7f8f631667d5
24-
SDWebImage: 7137d57385fb632129838c1e6ab9528a22c666cc
26+
SDWebImage: 6ac2eb96571bff96ecde31a987172c5934a0eb7d
2527
SDWebImageLinkPlugin: f77eb1f3ef322a2cb331ecf62cf78444529de597
2628

27-
PODFILE CHECKSUM: 74e009387008b3c98728da0575236586673f1fec
29+
PODFILE CHECKSUM: b080bcae01315fea0c82763be9711485ae91d032
2830

2931
COCOAPODS: 1.8.4

Example/SDWebImageLinkPlugin/SDViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ - (void)viewDidLoad {
8787
style:UIBarButtonItemStylePlain
8888
target:self
8989
action:@selector(switchView)];
90-
self.useLinkView = NO;
90+
self.useLinkView = YES;
9191
self.objects = [NSArray arrayWithObjects:
9292
@"https://www.apple.com/",
9393
@"https://www.apple.com/music/",

SDWebImageLinkPlugin/Classes/LPLinkView+WebCache.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ - (void)sd_setImageWithURL:(nullable NSURL *)url
6969
metadata = [[LPLinkMetadata alloc] init];
7070
metadata.originalURL = url;
7171
metadata.URL = imageURL;
72+
NSData *extendedData = image.sd_extendedData;
73+
if (extendedData) {
74+
NSString *title = [[NSString alloc] initWithData:extendedData encoding:NSUTF8StringEncoding];
75+
if (title.length > 0) {
76+
metadata.title = title;
77+
}
78+
}
7279
// LPLinkMetadata.imageProvider on iOS 13.1 contains bug which cause async query, and not compatible for cell-reusing. Radar FB7462933
7380
id<LPImageProtocol> linkImage = [[NSClassFromString(LPImageClass) alloc] initWithPlatformImage:image];
7481
[metadata setValue:linkImage forKey:@"image"];

SDWebImageLinkPlugin/Classes/SDImageLinkLoader.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ - (void)fetchImageDataWithProvider:(NSItemProvider *)imageProvider operation:(SD
154154
UIImage *image = SDImageLoaderDecodeImageData(data, url, options, context);
155155
if (!image) {
156156
error = [NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorBadImageData userInfo:nil];
157+
} else {
158+
LPLinkMetadata *metadata = url.sd_linkMetadata;
159+
image.sd_extendedData = [metadata.title dataUsingEncoding:NSUTF8StringEncoding];
157160
}
158161
if (completedBlock) {
159162
dispatch_main_async_safe(^{
@@ -192,6 +195,9 @@ - (void)fetchImageWithProvider:(NSItemProvider *)imageProvider operation:(SDImag
192195
NSAssert([image isKindOfClass:UIImage.class], @"NSItemProvider loaded object should be UIImage class");
193196
if (!image) {
194197
error = [NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorBadImageData userInfo:nil];
198+
} else {
199+
LPLinkMetadata *metadata = url.sd_linkMetadata;
200+
image.sd_extendedData = [metadata.title dataUsingEncoding:NSUTF8StringEncoding];
195201
}
196202
if (completedBlock) {
197203
dispatch_main_async_safe(^{

0 commit comments

Comments
 (0)