以下代码通过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 );
}
我误解了什么吗?这看起来很简单......
任何帮助表示赞赏!
答案 0 :(得分:0)
我也遇到了同样的问题,无法弄清楚这段代码有什么问题。我认为这个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];