gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:17:41 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com