Skip to content

Commit 2e9646f

Browse files
committed
Migrates AFNetworking image download to SDWebImage in order to use the cache
1 parent eceeec1 commit 2e9646f

File tree

148 files changed

+5274
-10032
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+5274
-10032
lines changed

Diff for: BFRImageViewController/BFRImageContainerViewController.m

+22-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
#import <Photos/Photos.h>
1212
#import <DACircularProgress/DACircularProgressView.h>
13-
#import "AFNetworking.h"
13+
#import "SDWebImageManager.h"
14+
#import "SDWebImageDownloader.h"
1415

1516
@interface BFRImageContainerViewController () <UIScrollViewDelegate, UIGestureRecognizerDelegate>
1617
@property (strong, nonatomic) UIScrollView *scrollView;
@@ -295,23 +296,27 @@ - (void)retrieveImageFromAsset {
295296
}
296297
- (void)retrieveImageFromURL {
297298
NSURL *url = (NSURL *)self.imgSrc;
298-
299-
AFHTTPSessionManager *imgOperation = [[AFHTTPSessionManager alloc] init];
300-
imgOperation.responseSerializer = [AFImageResponseSerializer serializer];
301-
302-
[imgOperation GET:url.absoluteString parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
303-
[self.progressView setProgress:downloadProgress.fractionCompleted];
304-
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
305-
self.imgLoaded = responseObject;
306-
[self addImageToScrollView];
307-
[self.progressView removeFromSuperview];
308-
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
309-
[self.progressView removeFromSuperview];
310-
311-
NSLog(@"error %@", error);
312-
313-
[self showError];
299+
300+
SDWebImageManager *manager = [SDWebImageManager sharedManager];
301+
[manager downloadImageWithURL:url options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
302+
float fractionCompleted = (float)receivedSize/(float)expectedSize;
303+
dispatch_async(dispatch_get_main_queue(), ^{
304+
[self.progressView setProgress:fractionCompleted];
305+
});
306+
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
307+
dispatch_async(dispatch_get_main_queue(), ^{
308+
if (error) {
309+
[self.progressView removeFromSuperview];
310+
NSLog(@"error %@", error);
311+
[self showError];
312+
return;
313+
}
314+
self.imgLoaded = image;
315+
[self addImageToScrollView];
316+
[self.progressView removeFromSuperview];
317+
});
314318
}];
319+
315320
}
316321

317322
- (void)showError {

Diff for: BFRImageViewer.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ Pod::Spec.new do |s|
1010
s.platform = :ios, '8.0'
1111
s.requires_arc = true
1212
s.dependency 'DACircularProgress'
13-
s.dependency 'AFNetworking'
13+
s.dependency 'SDWebImage'
1414
end

Diff for: BFRImageViewerDemo/Podfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
target 'BFRImageViewer' do
77

88
pod 'DACircularProgress'
9-
pod 'AFNetworking', '~> 3.0'
9+
pod 'SDWebImage', '~> 3.7'
1010

1111
end
1212

@@ -17,4 +17,3 @@ end
1717
target 'BFRImageViewerUITests' do
1818

1919
end
20-

Diff for: BFRImageViewerDemo/Podfile.lock

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
PODS:
2-
- AFNetworking (3.0.0):
3-
- AFNetworking/NSURLSession (= 3.0.0)
4-
- AFNetworking/Reachability (= 3.0.0)
5-
- AFNetworking/Security (= 3.0.0)
6-
- AFNetworking/Serialization (= 3.0.0)
7-
- AFNetworking/UIKit (= 3.0.0)
8-
- AFNetworking/NSURLSession (3.0.0):
9-
- AFNetworking/Reachability
10-
- AFNetworking/Security
11-
- AFNetworking/Serialization
12-
- AFNetworking/Reachability (3.0.0)
13-
- AFNetworking/Security (3.0.0)
14-
- AFNetworking/Serialization (3.0.0)
15-
- AFNetworking/UIKit (3.0.0):
16-
- AFNetworking/NSURLSession
172
- DACircularProgress (2.3.1)
3+
- SDWebImage (3.7.3):
4+
- SDWebImage/Core (= 3.7.3)
5+
- SDWebImage/Core (3.7.3)
186

197
DEPENDENCIES:
20-
- AFNetworking (~> 3.0)
218
- DACircularProgress
9+
- SDWebImage (~> 3.7)
2210

2311
SPEC CHECKSUMS:
24-
AFNetworking: 932ff751f9d6fb1dad0b3af58b7e3ffba0a4e7fd
2512
DACircularProgress: 4dd437c0fc3da5161cb289e07ac449493d41db71
13+
SDWebImage: 1d2b1a1efda1ade1b00b6f8498865f8ddedc8a84
2614

2715
COCOAPODS: 0.39.0

Diff for: BFRImageViewerDemo/Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.h

-295
This file was deleted.

0 commit comments

Comments
 (0)