Commit 293a1fa6 authored by yuzheng's avatar yuzheng

强壮下载完成的判断,避免PHImageErrorKey为NSNULL时回调不执行的问题

parent 06ed510b
...@@ -364,17 +364,13 @@ static dispatch_once_t onceToken; ...@@ -364,17 +364,13 @@ static dispatch_once_t onceToken;
imageSize = CGSizeMake(pixelWidth, pixelHeight); imageSize = CGSizeMake(pixelWidth, pixelHeight);
} }
__block UIImage *image;
// 修复获取图片时出现的瞬间内存过高问题 // 修复获取图片时出现的瞬间内存过高问题
// 下面两行代码,来自hsjcom,他的github是:https://github.com/hsjcom 表示感谢 // 下面两行代码,来自hsjcom,他的github是:https://github.com/hsjcom 表示感谢
PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init]; PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init];
option.resizeMode = PHImageRequestOptionsResizeModeFast; option.resizeMode = PHImageRequestOptionsResizeModeFast;
int32_t imageRequestID = [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:imageSize contentMode:PHImageContentModeAspectFill options:option resultHandler:^(UIImage *result, NSDictionary *info) { int32_t imageRequestID = [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:imageSize contentMode:PHImageContentModeAspectFill options:option resultHandler:^(UIImage *result, NSDictionary *info) {
if (result) { BOOL cancelled = [[info objectForKey:PHImageCancelledKey] boolValue];
image = result; if (!cancelled && result) {
}
BOOL downloadFinined = (![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey]);
if (downloadFinined && result) {
result = [self fixOrientation:result]; result = [self fixOrientation:result];
if (completion) completion(result,info,[[info objectForKey:PHImageResultIsDegradedKey] boolValue]); if (completion) completion(result,info,[[info objectForKey:PHImageResultIsDegradedKey] boolValue]);
} }
...@@ -395,8 +391,8 @@ static dispatch_once_t onceToken; ...@@ -395,8 +391,8 @@ static dispatch_once_t onceToken;
if (![TZImagePickerConfig sharedInstance].notScaleImage) { if (![TZImagePickerConfig sharedInstance].notScaleImage) {
resultImage = [self scaleImage:resultImage toSize:imageSize]; resultImage = [self scaleImage:resultImage toSize:imageSize];
} }
if (!resultImage) { if (!resultImage && result) {
resultImage = image; resultImage = result;
} }
resultImage = [self fixOrientation:resultImage]; resultImage = [self fixOrientation:resultImage];
if (completion) completion(resultImage,info,NO); if (completion) completion(resultImage,info,NO);
...@@ -441,8 +437,8 @@ static dispatch_once_t onceToken; ...@@ -441,8 +437,8 @@ static dispatch_once_t onceToken;
} }
option.resizeMode = PHImageRequestOptionsResizeModeFast; option.resizeMode = PHImageRequestOptionsResizeModeFast;
return [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeAspectFit options:option resultHandler:^(UIImage *result, NSDictionary *info) { return [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeAspectFit options:option resultHandler:^(UIImage *result, NSDictionary *info) {
BOOL downloadFinined = (![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey]); BOOL cancelled = [[info objectForKey:PHImageCancelledKey] boolValue];
if (downloadFinined && result) { if (!cancelled && result) {
result = [self fixOrientation:result]; result = [self fixOrientation:result];
BOOL isDegraded = [[info objectForKey:PHImageResultIsDegradedKey] boolValue]; BOOL isDegraded = [[info objectForKey:PHImageResultIsDegradedKey] boolValue];
if (completion) completion(result,info,isDegraded); if (completion) completion(result,info,isDegraded);
...@@ -464,8 +460,8 @@ static dispatch_once_t onceToken; ...@@ -464,8 +460,8 @@ static dispatch_once_t onceToken;
[option setProgressHandler:progressHandler]; [option setProgressHandler:progressHandler];
option.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; option.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
return [[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) { return [[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
BOOL downloadFinined = (![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey]); BOOL cancelled = [[info objectForKey:PHImageCancelledKey] boolValue];
if (downloadFinined && imageData) { if (!cancelled && imageData) {
if (completion) completion(imageData,info,NO); if (completion) completion(imageData,info,NO);
} }
}]; }];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment