ios - PhotoKit:fetchAssetCollectionsWithLocalIdentifiers 失败

标签 ios photokit

以下代码通过 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/

相关文章:

ios - 如何访问 iOS 上的视频输出功能?

ios - 如何使用 PhotoKit 列出共享照片流相册

objective-c - Photokit 中的元数据(EXIF、TIFF 等)

ios - 为什么 PHImageRequestOptions.progressHandler 从未被调用?

ios - 在 Swift 中将 NSMutableDictionary 转换为 NSData

ios - 向 uiview 添加从 A 点移动到 B 点的动画

ios - 如何解析 objective-c 中的xml响应

ios - 在对象库中找不到主视图 Controller 和详细 View Controller

cocoa-touch - 如何使用 PhotoKit 获取 iCloud 共享相册上的点赞详细信息