以下代码通过 3 个简单步骤突出显示了该问题:
1) 获取时刻
2)缓存时刻localIdentifier
3) 使用标识符获取时刻:失败(在设备上,iOS 8.2)
- ( void )momentLocalIdTest
{
PHFetchResult * fetchResult;
PHAssetCollection * moment;
NSString * localIdentifier;
fetchResult = [ PHAssetCollection fetchMomentsWithOptions: nil ];
if( fetchResult.count == 0 )
return;
moment = fetchResult.firstObject;
localIdentifier = moment.localIdentifier;
fetchResult = [ PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers: @[ localIdentifier ] options: nil ];
if( fetchResult.count == 0 )
NSLog( @"AssetCollection with localIdentifier %@ not found!!!", localIdentifier );
}
我是不是误会了什么?看起来很简单......
感谢任何帮助!
最佳答案
我也遇到了同样的问题,无法弄清楚这段代码有什么问题。我认为这个 API 很简单而且很简单(至少 8.0 到 8.4)
这是一个变通代码;您基本上必须从标识符中重新生成 PHAssetCollection 实例
PHFetchOptions *options = [PHFetchOptions new];
options.predicate = [NSPredicate predicateWithFormat:@"localIdentifier = %@", identifier];
PHAssetCollection *collection = [[PHAssetCollection fetchMomentsWithOptions:options] firstObject];
PHFetchResult *results = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
关于ios - PhotoKit:fetchAssetCollectionsWithLocalIdentifiers 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29275214/