PHImageManager requestImageForAsset返回非nil但不正确的结果

时间:2019-07-10 17:23:26

标签: objective-c xcode phasset

我有一个页面视图控制器,它准备了多个视图控制器(并且一次显示一个)。每个视图控制器基于资产的localIdentifier加载相应的资产。大多数情况下,它都能正常工作。但是,如果尝试加载从Mac的“相机胶卷”或“已同步的相册”中删除的资产,则视图控制器会自动关闭。资产最终排在本地标识符数组中的原因是,由于某种原因,该资产仍保留在“照片”应用程序的“时刻”选项卡中(但同样,它在“相机胶卷”或同步的相册中不存在)。

// Get the image
PHCachingImageManager *imageManager = [[PHCachingImageManager alloc] init];
CGSize targetSize = CGSizeZero;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    // iPhone
    targetSize = CGSizeMake(actualSizedImageRect.size.width,actualSizedImageRect.size.height);
} else {
    // iPad
    targetSize = CGSizeMake(2000,2000);
}
PHImageRequestOptions *options = [[PHImageRequestOptions alloc]init];
options.deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic;
options.resizeMode   = PHImageRequestOptionsResizeModeNone;
options.version      = PHImageRequestOptionsVersionCurrent;
options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *dictionary) {
    dispatch_async(dispatch_get_main_queue(), ^{
    });
};
[imageManager requestImageForAsset:self.asset
                             targetSize:targetSize
                            contentMode:PHImageContentModeAspectFit
                                options:options
                          resultHandler:^(UIImage *result, NSDictionary *info) {
                              dispatch_async(dispatch_get_main_queue(), ^{
                                  [self.assetImageView setImage:result]; //iwashere memo when a photo that no longer exists in albums (but in moments) is about to be presented, above result receives an incorrect image. That's probably causing issues with storyboard constraint so the view controller dismisses automatically.
                                  if (@available(iOS 11.0, *)){
                                      if (self.asset.playbackStyle == PHAssetPlaybackStyleLivePhoto){
                                          [self.assetImageView setHidden:YES];
                                      }
                                  }
                              });
                          }];

到目前为止,我发现上面的结果处理程序被调用了几次,最终它返回包含不同图像的结果,其不同尺寸会导致情节提要出现问题。因此,视图控制器只是将其关闭。

如果它返回nil,我可以简单地决定不将其加载到self.assetImageView,但是即使返回错误的图像,结果也不是nil。我想知道是否有办法确定返回的结果是否确实属于资产。

0 个答案:

没有答案
相关问题