了解如何从以下链接中检索iOS设备中的最后一张照片
How to retrieve the most recent photo from Camera Roll on iOS?
但是我想要检索最后20张照片,因为我不想减慢性能,让用户以相反的顺序查看他们的照片
我试过
long index = group.numberOfAssets - 2;
并结束此错误
由于未捕获的异常'NSRangeException'而终止应用程序,原因:'*** - [NSIndexSet initWithIndexesInRange:]:范围{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)
答案 0 :(得分: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
}
}];