Photos Framework requestImageDataForAsset occasionally fails

前端 未结 4 1840
不思量自难忘°
不思量自难忘° 2020-12-24 14:54

I\'m using the photos framework on iOS8.1 and requesting the image data for the asset using requestImageDataForAsset... Most of the time it works and I get the image data an

4条回答
  •  长发绾君心
    2020-12-24 15:27

    Getting back to this after a long while, I have solved a big part of my problem. No mystery, just bad code:

    PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[urlMedia] options:nil];
    PHAsset *asset = [result firstObject];
    
    if (asset != nil) { // the fix
        PHImageManager *imageManager = [PHImageManager defaultManager];
        PHImageRequestOptions *options = [[PHImageRequestOptions alloc]init];
        ...
    }
    

    The most common cause for me was a problem with the media URL passed to fetchAssetsWithALAssetURLs causing asset to be nil and requestImageDataForAsset return a default info object.

提交回复
热议问题