Photos Framework requestImageDataForAsset occasionally fails

前端 未结 4 1844
不思量自难忘°
不思量自难忘° 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:06

    The following code maybe help. I think the class PHImageRequestOptions has a bug, so I pass nil , and then fix the bug.

       dispatch_semaphore_t sema = dispatch_semaphore_create(0);
                [[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                    assetModel.size = imageData.length;
                    NSString *filename = [asset valueForKey:@"filename"];
                    assetModel.fileName = filename;
                    dispatch_semaphore_signal(sema);
                }];
                dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
    

提交回复
热议问题