Skip to content

Commit 00bf6ee

Browse files
committed
加载网络图片统一用sd库
1 parent 3d43dd7 commit 00bf6ee

File tree

4 files changed

+18
-33
lines changed

4 files changed

+18
-33
lines changed

Coding_iOS/AppDelegate.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
6161
[[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
6262
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
6363

64+
//sd加载的数据类型
65+
[[[SDWebImageManager sharedManager] imageDownloader] setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
66+
6467
//设置导航条样式
6568
[self customizeInterface];
6669

67-
6870
if ([Login isLogin]) {
6971
[self setupTabViewController];
7072
}else{

Coding_iOS/Vendor/MJPhotoBrowser/MJPhotoView.m

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#import <QuartzCore/QuartzCore.h>
1212
#import "YLGIFImage.h"
1313
#import "YLImageView.h"
14-
#import "UIImageView+AFNetworking.h"
1514

1615
@interface MJPhotoView ()
1716
{
@@ -95,32 +94,17 @@ - (void)photoStartLoad
9594
ESWeak_(_photoLoadingView);
9695
ESWeak_(_imageView);
9796

98-
if ([_photo.url.absoluteString rangeOfString:@"imagePreview"].location != NSNotFound) {
99-
[_imageView setImageWithURLRequest:[[NSURLRequest alloc] initWithURL:_photo.url] placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
100-
ESStrongSelf;
101-
ESStrong_(_imageView);
102-
__imageView.image = image;
103-
[_self photoDidFinishLoadWithImage:image];
104-
105-
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
106-
ESStrongSelf;
107-
ESStrong_(_imageView);
108-
__imageView.image = nil;
109-
[_self photoDidFinishLoadWithImage:nil];
110-
}];
111-
}else{
112-
[SDWebImageManager.sharedManager downloadImageWithURL:_photo.url options:SDWebImageRetryFailed|SDWebImageLowPriority| SDWebImageHandleCookies progress:^(NSInteger receivedSize, NSInteger expectedSize) {
113-
ESStrong_(_photoLoadingView);
114-
if (receivedSize > kMinProgress) {
115-
__photoLoadingView.progress = (float)receivedSize/expectedSize;
116-
}
117-
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
118-
ESStrongSelf;
119-
ESStrong_(_imageView);
120-
__imageView.image = image;
121-
[_self photoDidFinishLoadWithImage:image];
122-
}];
123-
}
97+
[SDWebImageManager.sharedManager downloadImageWithURL:_photo.url options:SDWebImageRetryFailed| SDWebImageLowPriority| SDWebImageHandleCookies progress:^(NSInteger receivedSize, NSInteger expectedSize) {
98+
ESStrong_(_photoLoadingView);
99+
if (receivedSize > kMinProgress) {
100+
__photoLoadingView.progress = (float)receivedSize/expectedSize;
101+
}
102+
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
103+
ESStrongSelf;
104+
ESStrong_(_imageView);
105+
__imageView.image = image;
106+
[_self photoDidFinishLoadWithImage:image];
107+
}];
124108
}
125109
}
126110

Coding_iOS/Views/CCell/TaskCommentCCell.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define kTaskCommentCCell_Width 33.0
1010

1111
#import "TaskCommentCCell.h"
12-
#include "UIImageView+AFNetworking.h"
1312

1413
@implementation TaskCommentCCell
1514
- (id)initWithFrame:(CGRect)frame
@@ -36,7 +35,7 @@ - (void)setCurMediaItem:(HtmlMediaItem *)curMediaItem{
3635

3736
if (_curMediaItem != curMediaItem) {
3837
_curMediaItem = curMediaItem;
39-
[self.imgView setImageWithURLRequest:[[NSURLRequest alloc] initWithURL:[_curMediaItem.src urlImageWithCodePathResize:2*kTaskCommentCCell_Width]] placeholderImage:kPlaceholderCodingSquareWidth(55.0) success:nil failure:nil];
38+
[self.imgView sd_setImageWithURL:[_curMediaItem.src urlImageWithCodePathResize:2*kTaskCommentCCell_Width] placeholderImage:kPlaceholderCodingSquareWidth(55.0) options:SDWebImageRetryFailed| SDWebImageLowPriority| SDWebImageHandleCookies];
4039
}
4140
}
4241

Coding_iOS/Views/FileDownloadView.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#import "FileDownloadView.h"
1010
#import "ASProgressPopUpView.h"
1111
#import "Coding_FileManager.h"
12-
#import "UIImageView+AFNetworking.h"
1312
#import "YLImageView.h"
1413

1514
@interface FileDownloadView ()
@@ -39,8 +38,9 @@ - (void)setFile:(ProjectFile *)file{
3938
[self loadLayoutWithCurFile];
4039

4140
if (_file.preview && _file.preview.length > 0) {
42-
43-
[_iconView setImageWithURLRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:_file.owner_preview]] placeholderImage:nil success:nil failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
41+
[_iconView sd_setImageWithURL:[NSURL URLWithString:_file.owner_preview] placeholderImage:nil options:SDWebImageRetryFailed| SDWebImageLowPriority| SDWebImageHandleCookies progress:^(NSInteger receivedSize, NSInteger expectedSize) {
42+
43+
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
4444
if (error) {
4545
[error showError:error];
4646
}

0 commit comments

Comments
 (0)