Skip to content

Migrates AFNetworking image download to SDWebImage in order to use th… #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions BFRImageViewController/BFRImageContainerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

#import <Photos/Photos.h>
#import <DACircularProgress/DACircularProgressView.h>
#import "AFNetworking.h"
#import "SDWebImageManager.h"
#import "SDWebImageDownloader.h"

@interface BFRImageContainerViewController () <UIScrollViewDelegate, UIGestureRecognizerDelegate>
@property (strong, nonatomic) UIScrollView *scrollView;
Expand Down Expand Up @@ -295,23 +296,27 @@ - (void)retrieveImageFromAsset {
}
- (void)retrieveImageFromURL {
NSURL *url = (NSURL *)self.imgSrc;

AFHTTPSessionManager *imgOperation = [[AFHTTPSessionManager alloc] init];
imgOperation.responseSerializer = [AFImageResponseSerializer serializer];

[imgOperation GET:url.absoluteString parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
[self.progressView setProgress:downloadProgress.fractionCompleted];
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
self.imgLoaded = responseObject;
[self addImageToScrollView];
[self.progressView removeFromSuperview];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[self.progressView removeFromSuperview];

NSLog(@"error %@", error);

[self showError];

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:url options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
float fractionCompleted = (float)receivedSize/(float)expectedSize;
dispatch_async(dispatch_get_main_queue(), ^{
[self.progressView setProgress:fractionCompleted];
});
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
[self.progressView removeFromSuperview];
NSLog(@"error %@", error);
[self showError];
return;
}
self.imgLoaded = image;
[self addImageToScrollView];
[self.progressView removeFromSuperview];
});
}];

}

- (void)showError {
Expand Down
2 changes: 1 addition & 1 deletion BFRImageViewer.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Pod::Spec.new do |s|
s.platform = :ios, '8.0'
s.requires_arc = true
s.dependency 'DACircularProgress'
s.dependency 'AFNetworking'
s.dependency 'SDWebImage'
end
3 changes: 1 addition & 2 deletions BFRImageViewerDemo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
target 'BFRImageViewer' do

pod 'DACircularProgress'
pod 'AFNetworking', '~> 3.0'
pod 'SDWebImage', '~> 3.7'

end

Expand All @@ -17,4 +17,3 @@ end
target 'BFRImageViewerUITests' do

end

22 changes: 5 additions & 17 deletions BFRImageViewerDemo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
PODS:
- AFNetworking (3.0.0):
- AFNetworking/NSURLSession (= 3.0.0)
- AFNetworking/Reachability (= 3.0.0)
- AFNetworking/Security (= 3.0.0)
- AFNetworking/Serialization (= 3.0.0)
- AFNetworking/UIKit (= 3.0.0)
- AFNetworking/NSURLSession (3.0.0):
- AFNetworking/Reachability
- AFNetworking/Security
- AFNetworking/Serialization
- AFNetworking/Reachability (3.0.0)
- AFNetworking/Security (3.0.0)
- AFNetworking/Serialization (3.0.0)
- AFNetworking/UIKit (3.0.0):
- AFNetworking/NSURLSession
- DACircularProgress (2.3.1)
- SDWebImage (3.7.3):
- SDWebImage/Core (= 3.7.3)
- SDWebImage/Core (3.7.3)

DEPENDENCIES:
- AFNetworking (~> 3.0)
- DACircularProgress
- SDWebImage (~> 3.7)

SPEC CHECKSUMS:
AFNetworking: 932ff751f9d6fb1dad0b3af58b7e3ffba0a4e7fd
DACircularProgress: 4dd437c0fc3da5161cb289e07ac449493d41db71
SDWebImage: 1d2b1a1efda1ade1b00b6f8498865f8ddedc8a84

COCOAPODS: 0.39.0

This file was deleted.

Loading