ios - 从 iPhone 检索最后几张照片

标签 ios objective-c

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

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

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

我试过了

long index = group.numberOfAssets - 2;

并以这个错误结束

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSIndexSet initWithIndexesInRange:]: Range {4294967294, 1} exceeds maximum index value of 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)

最佳答案

可能是你列举的方式不对。 此代码获取最后一张图片

    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
             }

     }];

关于ios - 从 iPhone 检索最后几张照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15277225/

相关文章:

ios - 子类化 Typhoon 程序集以覆盖不起作用的方法

ios - Quartz Core 绘制一些图元

php - 如何将 PHP 中的 MySql 数据放入 Cocoa 应用程序 TableView

ios - 此方法中的内存泄漏在哪里?

ios - 动态显示来自服务 Objective-C 的状态消息

ios - Xcode 7 Swift 2 对象大小在运行时不同

ios - 用 Swift 解析 : handle network error manually

ios - 使 UILabel 文本可点击

ios - id delegate unrecognized selector 发送到实例

iphone - 迁移核心数据——如何安全地迁移?