首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PhotoKit: fetchAssetCollectionsWithLocalIdentifiers失败

PhotoKit: fetchAssetCollectionsWithLocalIdentifiers失败
EN

Stack Overflow用户
提问于 2015-03-26 17:42:58
回答 1查看 973关注 0票数 5

下面的代码通过3个简单的步骤突出显示了这个问题:

1)获取moments

2)缓存时刻localIdentifier

3)获取带有标识符的时刻:失败(在设备上,iOS 8.2 )

代码语言:javascript
复制
- ( 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 );
}

我是不是误解了什么?这看起来很简单。

感谢任何人的帮助!

EN

回答 1

Stack Overflow用户

发布于 2015-07-23 22:52:32

我也遇到了同样的问题,不知道这段代码出了什么问题。我认为这个API就是简单的破解(至少8.0到8.4 )

下面是一个变通方法代码;您基本上必须从标识符重新生成PHAssetCollection实例

代码语言:javascript
复制
PHFetchOptions *options = [PHFetchOptions new];
options.predicate = [NSPredicate predicateWithFormat:@"localIdentifier = %@", identifier];

PHAssetCollection *collection = [[PHAssetCollection fetchMomentsWithOptions:options] firstObject];
PHFetchResult *results = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29275214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档