Skip to content
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

feat: 支持auth header #127

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 4 additions & 10 deletions GKPhotoBrowser/Core/GKPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,15 @@ - (void)layoutSubviews {
}else {
CGFloat centerX = self.contentView.bounds.size.width * 0.5f;

self.countLabel.center = CGPointMake(centerX, (KIsiPhoneX && !self.isLandscape) ? 50 : 30);
self.countLabel.center = CGPointMake(centerX, (KIsiPhoneX && !self.isLandscape) ? 65 : 30);
CGFloat pointY = 0;
if (self.isLandscape) {
pointY = self.contentView.bounds.size.height - 20;
}else {
pointY = self.contentView.bounds.size.height - 10 - (self.isAdaptiveSafeArea ? 0 : kSafeBottomSpace);
}
self.pageControl.center = CGPointMake(centerX, pointY);
self.saveBtn.center = CGPointMake(self.contentView.bounds.size.width - 50, pointY);
self.saveBtn.center = CGPointMake(self.contentView.bounds.size.width - 30, pointY - 10);
}

if ([self.delegate respondsToSelector:@selector(photoBrowser:willLayoutSubViews:)]) {
Expand Down Expand Up @@ -1416,14 +1416,8 @@ - (UIPageControl *)pageControl {
- (UIButton *)saveBtn {
if (!_saveBtn) {
UIButton *saveBtn = [UIButton new];
saveBtn.bounds = CGRectMake(0, 0, 50, 30);
[saveBtn setTitle:@"保存" forState:UIControlStateNormal];
[saveBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
saveBtn.titleLabel.font = [UIFont systemFontOfSize:15.0f];
saveBtn.layer.cornerRadius = 5;
saveBtn.layer.masksToBounds = YES;
saveBtn.layer.borderColor = UIColor.whiteColor.CGColor;
saveBtn.layer.borderWidth = 1;
saveBtn.bounds = CGRectMake(0, 0, 20, 20);
[saveBtn setBackgroundImage:GKPhotoBrowserImage(@"icon_download") forState:UIControlStateNormal];
saveBtn.hidden = YES;
[saveBtn addTarget:self action:@selector(saveBtnClick:) forControlEvents:UIControlEventTouchUpInside];
_saveBtn = saveBtn;
Expand Down
6 changes: 6 additions & 0 deletions GKPhotoBrowser/Core/GKPhotoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ NS_ASSUME_NONNULL_BEGIN
/** 占位图 */
@property (nonatomic, strong, nullable) UIImage *placeholderImage;

/** originUrl 权限header */
@property (nonatomic, strong, nullable) NSDictionary *originAuthToken;

/** url 权限header */
@property (nonatomic, strong, nullable) NSDictionary *authToken;


/************************内部使用,无需关心 ********************/
/** 图片是否加载完成 */
Expand Down
5 changes: 4 additions & 1 deletion GKPhotoBrowser/Core/GKPhotoView.m
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,13 @@ - (void)loadImageWithPhoto:(GKPhoto *)photo isOrigin:(BOOL)isOrigin {
}

NSURL *url = nil;
NSDictionary *authToken = nil;
if (photo.originFinished) {
url = photo.originUrl;
authToken = photo.originAuthToken;
}else {
url = isOrigin ? photo.originUrl : photo.url;
authToken = isOrigin ? photo.originAuthToken : photo.authToken;
}

if (url.absoluteString.length > 0) {
Expand Down Expand Up @@ -269,7 +272,7 @@ - (void)loadImageWithPhoto:(GKPhoto *)photo isOrigin:(BOOL)isOrigin {
});
};

[_imageProtocol setImageForImageView:self.imageView url:url placeholderImage:placeholderImage progress:progressBlock completion:completionBlock];
[_imageProtocol setImageForImageView:self.imageView url:url authToken:authToken placeholderImage:placeholderImage progress:progressBlock completion:completionBlock];
}else {
if (self.imageView.image) {
photo.finished = YES;
Expand Down
2 changes: 2 additions & 0 deletions GKPhotoBrowser/Core/GKWebImageProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ typedef void (^GKWebImageCompletionBlock)(UIImage * _Nullable image, NSURL * _Nu
/// 为imageView设置图片
/// @param imageView imageView
/// @param url 图片url
/// @param auth 图片的权限
/// @param placeholderImage 缺省图片
/// @param progressBlock 加载进度
/// @param completionBlock 完成进度
- (void)setImageForImageView:(nullable UIImageView *)imageView
url:(nullable NSURL *)url
authToken:(nullable NSDictionary *)auth
placeholderImage:(nullable UIImage *)placeholderImage
progress:(nullable GKWebImageProgressBlock)progressBlock
completion:(nullable GKWebImageCompletionBlock)completionBlock;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion GKPhotoBrowser/SDWebImage/GKSDWebImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ - (Class)imageViewClass {
return SDAnimatedImageView.class;
}

- (void)setImageForImageView:(UIImageView *)imageView url:(NSURL *)url placeholderImage:(UIImage *)placeholderImage progress:(GKWebImageProgressBlock)progress completion:(GKWebImageCompletionBlock)completion {
- (void)setImageForImageView:(UIImageView *)imageView url:(NSURL *)url authToken:(NSDictionary *)token placeholderImage:(UIImage *)placeholderImage progress:(GKWebImageProgressBlock)progress completion:(GKWebImageCompletionBlock)completion {

SDWebImageDownloader *manager = [SDWebImageManager sharedManager].imageLoader;
for (NSString *key in token) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没做放空处理

[manager setValue:[token objectForKey:key] forHTTPHeaderField:key];
}

[imageView sd_setImageWithURL:url placeholderImage:placeholderImage options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
!progress ? : progress(receivedSize, expectedSize);
} completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
Expand Down