4
我想獲取位於iOS設備上的圖片的固定批次。我現在用的是新Photos Framework,我已經發現了這個解決辦法:獲取批量的iOS圖片
PHFetchOptions *allPhotosOptions = [PHFetchOptions new];
allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
// Fetches all photos -> i would like to fetch only some of them
PHFetchResult *allPhotosResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosOptions];
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(currentIndex, batch_size)];
// Iterates over a subset of the previously fetched photos
[allPhotosResult enumerateObjectsAtIndexes:indexSet options:0 usingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop)
{
// Do stuff
}
它工作正常,但我第一次提取所有的照片fetchAssetsWithMediaType
,然後選擇結果的一個子集,我的應用程序加載,這似乎相當重...
我想知道是否有一種方法可以直接讀取照片逐批,而不是獲取再把它們重複。 此外,如果我可以保留最後一批獲取的批次的索引,知道將在哪裏獲取下一批,那將是完美的。
感謝您的幫助!