ios - requestImageDataForAsset 带有视频 PHAsset 返回带有指向照片的 imageData
<p><p>iOS9.3beta3,</p>
<p>PHImageManager requestImageDataForAsset 返回指向照片的 imageData,尽管 PHAssert 是在设备上捕获的<strong>视频</strong> Assets 。</p>
<p>文档 <a href="https://developer.apple.com/library/prerelease/ios/documentation/Photos/Reference/PHImageManager_Class/index.html#//apple_ref/occ/instm/PHImageManager/requestImageDataForAsset:options:resultHandler:" rel="noreferrer noopener nofollow">says</a> :</p>
<blockquote>
<p>"requestImageDataForAsset(_:options:resultHandler:)</p>
<p>... 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
<strong>originally captured image data for the asset</strong>."</p>
</blockquote>
<p>这是 iOS9.3 的 bug 吗?</p>
<p>阿米尔。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>对我来说简单的解决方案</p>
<pre><code>+ (void)getAssetData:(NSString *)ident completeBlock:(void (^)(NSData *assetData))completeBlock {
PHFetchResult *fetchResult = options:nil];
if (fetchResult && == 0) {
if (completeBlock) {
completeBlock(nil);
}
return;
}
PHAsset *asset = fetchResult.firstObject;
if (asset.mediaType == PHAssetMediaTypeVideo) {
[ requestAVAssetForVideo:asset options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
if (]) {
AVURLAsset* urlAsset = (AVURLAsset*)asset;
NSNumber *size;
;
NSData *data = ;
completeBlock(data);
} else {
completeBlock(nil);
}
}];
} else {
[ requestImageDataForAsset:fetchResult.firstObject options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
completeBlock(imageData);
}];
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - requestImageDataForAsset 带有视频 PHAsset 返回带有指向照片的 imageData,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35494169/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35494169/
</a>
</p>
页:
[1]