diff --git a/Classes/IDMPhoto.h b/Classes/IDMPhoto.h index 3de62427..dbc9241b 100644 --- a/Classes/IDMPhoto.h +++ b/Classes/IDMPhoto.h @@ -8,7 +8,7 @@ #import #import "IDMPhotoProtocol.h" -#import "AFNetworking.h" +#import // This class models a photo/image and it's caption // If you want to handle photos, caching, decompression diff --git a/Classes/IDMPhoto.m b/Classes/IDMPhoto.m index d37d1dc5..29481a43 100644 --- a/Classes/IDMPhoto.m +++ b/Classes/IDMPhoto.m @@ -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; diff --git a/Demo/Podfile b/Demo/Podfile index a7967908..e7d704ad 100644 --- a/Demo/Podfile +++ b/Demo/Podfile @@ -6,7 +6,7 @@ inhibit_all_warnings! target "PhotoBrowserDemo" do -pod 'AFNetworking' +pod 'SDWebImage' pod 'DACircularProgress' pod 'pop' diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock index 8f8017ae..725c71b1 100644 --- a/Demo/Podfile.lock +++ b/Demo/Podfile.lock @@ -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 diff --git a/IDMPhotoBrowser.podspec b/IDMPhotoBrowser.podspec index 0f36fc92..8fa04491 100644 --- a/IDMPhotoBrowser.podspec +++ b/IDMPhotoBrowser.podspec @@ -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