Skip to content

Commit

Permalink
Update MWPhoto.m
Browse files Browse the repository at this point in the history
  • Loading branch information
iamqk authored Sep 2, 2022
1 parent 243b69e commit 7541973
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Pod/Classes/MWPhoto.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ - (void)performLoadUnderlyingImageAndNotify {
- (void)_performLoadUnderlyingImageAndNotifyWithWebURL:(NSURL *)url {
@try {
SDWebImageManager *manager = [SDWebImageManager sharedManager];
/*
_webImageOperation = [manager downloadImageWithURL:url
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
Expand All @@ -233,6 +234,28 @@ - (void)_performLoadUnderlyingImageAndNotifyWithWebURL:(NSURL *)url {
[self imageLoadingComplete];
});
}];
*/
_webImageOperation = [manager loadImageWithURL:url
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
if (expectedSize > 0) {
float progress = receivedSize / (float)expectedSize;
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:progress], @"progress",
self, @"photo", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:MWPHOTO_PROGRESS_NOTIFICATION object:dict];
}
}
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
if (error) {
MWLog(@"SDWebImage failed to download image: %@", error);
}
_webImageOperation = nil;
self.underlyingImage = image;
dispatch_async(dispatch_get_main_queue(), ^{
[self imageLoadingComplete];
});
}];
} @catch (NSException *e) {
MWLog(@"Photo from web: %@", e);
_webImageOperation = nil;
Expand Down

0 comments on commit 7541973

Please sign in to comment.