OGeek|极客世界-中国程序员成长平台

标题: ios - requestImageDataForAsset 带有视频 PHAsset 返回带有指向照片的 imageData [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 14:34
标题: ios - requestImageDataForAsset 带有视频 PHAsset 返回带有指向照片的 imageData

iOS9.3beta3,

PHImageManager requestImageDataForAsset 返回指向照片的 imageData,尽管 PHAssert 是在设备上捕获的视频 Assets 。

文档 ptions:resultHandler:" rel="noreferrer noopener nofollow">says :

"requestImageDataForAsset(_ptions:resultHandler

... If the version option is set to PHImageRequestOptionsVersionCurrent, Photos provides rendered image data, including the results of any edits that have been made to the asset content. Otherwise, Photos provides the originally captured image data for the asset."

这是 iOS9.3 的 bug 吗?

阿米尔。



Best Answer-推荐答案


对我来说简单的解决方案

+ (void)getAssetDataNSString *)ident completeBlockvoid (^)(NSData *assetData))completeBlock {
    PHFetchResult *fetchResult = [PHAsset fetchAssetsWithLocalIdentifiers[ident] options:nil];
    if (fetchResult && [fetchResult count] == 0) {
        if (completeBlock) {
            completeBlock(nil);
        }
        return;
    }

    PHAsset *asset = fetchResult.firstObject;
    if (asset.mediaType == PHAssetMediaTypeVideo) {
        [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
            if ([asset isKindOfClass:[AVURLAsset class]]) {
                AVURLAsset* urlAsset = (AVURLAsset*)asset;
                NSNumber *size;
                [urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
                NSData *data = [NSData dataWithContentsOfURL:urlAsset.URL];
                completeBlock(data);
            } else {
                completeBlock(nil);
            }
        }];
    } else {
        [[PHImageManager defaultManager] requestImageDataForAsset:fetchResult.firstObject options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
            completeBlock(imageData);
        }];
    }
}

关于ios - requestImageDataForAsset 带有视频 PHAsset 返回带有指向照片的 imageData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35494169/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4