1and2papa / CTAssetsPickerController

iOS control that allows picking multiple photos and videos from user's photo library.
MIT License
2.15k stars 550 forks source link

Thumbnails does not work. #217

Closed maimaiworks closed 8 years ago

maimaiworks commented 8 years ago

Thumbnails does not work. app target :iPhone Test on iPadAir, iPadAir2,iPadPro.

simulator screen shot 2016 03 24 16 54 04 simulator screen shot 2016 03 24 16 54 24 buildsetting

krusek commented 8 years ago

@chiunam if you're interested in a fix, I can create a PR. It's pretty easy (I already troubleshot this for some other areas of my own app).

The basic issue is that on iPads in iPhone mode for iOS 9.3+ calls to:

- (PHImageRequestID)requestImageForAsset:(PHAsset *)asset targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:(nullable PHImageRequestOptions *)options resultHandler:(void (^)(UIImage *__nullable result, NSDictionary *__nullable info))resultHandler;

don't work if the dimensions on targetSize are less than about 500.

1and2papa commented 8 years ago

Hi @krusek. Really thanks for your help.

jiaowochunge commented 8 years ago

i pull the latest commit, failed to resolve the problem. i run the example(demo code) in simulater, the result just same as the issue description. i think the answer in http://stackoverflow.com/questions/28369400/phimagemanager-requestimageforasset-returns-nil-when-creating-thumbnail-for-vide may explain the problem. but i cant find the cause, why this problem happened in iPad only. According to the answer above, i set PHImageRequestOptions.networkAccessAllowed = YES, then the thumbnail image is ok, not return nil any more. still another problem, the photo broswer not work well.

jiaowochunge commented 8 years ago

实在是英文很差,设置了 PHImageRequestOptions.networkAccessAllowed = YES 参数后,缩略图能正常显示,图片浏览器有问题。横向照片能正常显示,纵向照片无法显示。我调试了下源码,CTAssetItemViewController.m 中的请求图片逻辑如下 `- (void)requestAssetImage { [self.scrollView setProgress:0];

CGSize targetSize = [self targetImageSize];
PHImageRequestOptions *options = [self imageRequestOptions];

self.imageRequestID =
[self.imageManager ctassetsPickerRequestImageForAsset:self.asset
                             targetSize:targetSize
                            contentMode:PHImageContentModeAspectFit
                                options:options
                          resultHandler:^(UIImage *image, NSDictionary *info) {

                              // this image is set for transition animation
                              self.image = image;

                              dispatch_async(dispatch_get_main_queue(), ^{

                                  NSError *error = info[PHImageErrorKey];

                                  if (error)
                                      [self showRequestImageError:error title:nil];
                                  else
                                      [self.scrollView bind:self.asset image:image requestInfo:info];
                              });
                          }];

}` 我修改了一些地方,targetSize 参数,使用系统提供的表示全图的参数 PHImageManagerMaximumSize ,貌似幸运的解决了问题。并没有完整测试。bug原因也没搞明白。

jiaowochunge commented 8 years ago

昨天已经有点头昏了。第一个回复,不能解决问题。让我误以为解决了,因为iPad模拟器有差异。大致测试了四个iPad模拟器,iPad2, iPad Air, iPad Air2, iPad Pro. 正如问题描述人所描述的,出现问题的是 iPad Air, iPad Air2, iPad Pro, 而iPad2是显示正常的。跟那个fix无关。

因为项目需要紧急修复,我找不到原因,只能做个小小修改,让这个问题看起来暂时没这么严重。 CTAssetsPickerController.m 文件中,- (void)initThumbnailRequestOptions 这个方法,将 PHImageRequestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; => PHImageRequestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat; 牺牲了缩略图的图像质量,但至少能显示了。这个回答主要是纠正上面错误的回答,上面那第二个回复,好像没什么大问题。