【问题标题】:retrieve last few photos from iPhone从 iPhone 检索最后几张照片
【发布时间】:2013-03-07 17:00:25
【问题描述】:

了解如何通过以下链接从 iOS 设备中检索最后一张照片

How to retrieve the most recent photo from Camera Roll on iOS?

但我想检索最后 20 张左右的照片,因为我不想降低性能,也不想让用户以相反的顺序查看他们的照片

我试过了

long index = group.numberOfAssets - 2;

并以这个错误结束

由于未捕获的异常 'NSRangeException' 导致应用程序终止,原因:'*** -[NSIndexSet initWithIndexesInRange:]: Range {4294967294, 1} 超过 NSNotFound 的最大索引值 - 1'

有人可以帮忙吗?谢谢

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

    [group setAssetsFilter:[ALAssetsFilter allPhotos]];

    ***long index              = group.numberOfAssets - 2;***
    [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:index]
                            options:0
                         usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop)

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    可能是您以错误的方式枚举。 This code gets the last image

        ALAssetsGroup* group = [groups lastObject]; // get all assets groups, i think you know how to get them.
        [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:(group.numberOfAssets - 1)] options:NSEnumerationConcurrent usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
         {
             if(result) {
                      // result is your needed last asset
                 }
    
         }];
    

    【讨论】:

    • 我了解如何获取最后一张照片。我试图获取最后一张照片,但因该错误而失败。不太确定 NSindexSet 限制。
    • 如果您确定索引一切正常,请添加 NSEnumerationConcurrent 选项
    • 有没有人得到完美的解决方案。
    • 我使用“enumerateAssetsWithOptions:NSEnumerationReverse”向后提取照片并为这些照片提供“索引”。然后我将它们发送到视图并以缩略图的形式呈现。一旦用户单击缩略图照片。照片将根据我标记的“索引”从库中提取。
    猜你喜欢
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-31
    • 1970-01-01
    • 2020-01-13
    相关资源
    最近更新 更多