了解如何通过以下链接从 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/