Skip to content

Commit

Permalink
Use SDWebImage instead of AFNetworking
Browse files Browse the repository at this point in the history
  • Loading branch information
satococoa committed Aug 12, 2014
1 parent 9f5fdd7 commit 838d6cd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Classes/IDMPhoto.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>
#import "IDMPhotoProtocol.h"
#import "AFNetworking.h"
#import <SDWebImage/SDWebImageManager.h>

// This class models a photo/image and it's caption
// If you want to handle photos, caching, decompression
Expand Down
28 changes: 10 additions & 18 deletions Classes/IDMPhoto.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,20 @@ - (void)loadUnderlyingImageAndNotify {
// Load async from file
[self performSelectorInBackground:@selector(loadImageFromFileAsync) withObject:nil];
} else if (_photoURL) {
// Load async from web (using AFNetworking)
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:_photoURL
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:0];

AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFImageResponseSerializer serializer];

[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
UIImage *image = responseObject;
self.underlyingImage = image;
[self performSelectorOnMainThread:@selector(imageLoadingComplete) withObject:nil waitUntilDone:NO];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { }];

[op setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
CGFloat progress = ((CGFloat)totalBytesRead)/((CGFloat)totalBytesExpectedToRead);
// Load async from web (using SDWebImageManager)
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:_photoURL options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) {
CGFloat progress = ((CGFloat)receivedSize)/((CGFloat)expectedSize);
if (self.progressUpdateBlock) {
self.progressUpdateBlock(progress);
}
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (image) {
self.underlyingImage = image;
[self performSelectorOnMainThread:@selector(imageLoadingComplete) withObject:nil waitUntilDone:NO];
}
}];

[[NSOperationQueue mainQueue] addOperation:op];

} else {
// Failed - no source
self.underlyingImage = nil;
Expand Down
2 changes: 1 addition & 1 deletion Demo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ inhibit_all_warnings!

target "PhotoBrowserDemo" do

pod 'AFNetworking'
pod 'SDWebImage'
pod 'DACircularProgress'
pod 'pop'

Expand Down
28 changes: 5 additions & 23 deletions Demo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
PODS:
- AFNetworking (2.3.1):
- AFNetworking/NSURLConnection
- AFNetworking/NSURLSession
- AFNetworking/Reachability
- AFNetworking/Security
- AFNetworking/Serialization
- AFNetworking/UIKit
- AFNetworking/NSURLConnection (2.3.1):
- AFNetworking/Reachability
- AFNetworking/Security
- AFNetworking/Serialization
- AFNetworking/NSURLSession (2.3.1):
- AFNetworking/Reachability
- AFNetworking/Security
- AFNetworking/Serialization
- AFNetworking/Reachability (2.3.1)
- AFNetworking/Security (2.3.1)
- AFNetworking/Serialization (2.3.1)
- AFNetworking/UIKit (2.3.1):
- AFNetworking/NSURLConnection
- AFNetworking/NSURLSession
- DACircularProgress (2.2.0)
- pop (1.0.6)
- SDWebImage (3.7.1):
- SDWebImage/Core
- SDWebImage/Core (3.7.1)

DEPENDENCIES:
- AFNetworking
- DACircularProgress
- pop
- SDWebImage

SPEC CHECKSUMS:
AFNetworking: 6d7b76aa5d04c8c37daad3eef4b7e3f2a7620da3
DACircularProgress: 3b41941891a56dc6aa17971f5322a9a38a6f446e
pop: e518794da38942c05255eb64b36d894e70cb4f00
SDWebImage: 116e88633b5b416ea0ca4b334a4ac59cf72dd38d

COCOAPODS: 0.33.1
2 changes: 1 addition & 1 deletion IDMPhotoBrowser.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Pod::Spec.new do |s|
s.resources = 'Classes/IDMPhotoBrowser.bundle', 'Classes/IDMPBLocalizations.bundle'
s.framework = 'MessageUI', 'QuartzCore', 'SystemConfiguration', 'MobileCoreServices', 'Security'
s.requires_arc = true
s.dependency 'AFNetworking'
s.dependency 'SDWebImage'
s.dependency 'DACircularProgress'
s.dependency 'pop'
end

0 comments on commit 838d6cd

Please sign in to comment.