2016-09-22 38 views
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,然后选择结果的一个子集,我的应用程序加载,这似乎相当重...

我想知道是否有一种方法可以直接读取照片逐批,而不是获取再把它们重复。 此外,如果我可以保留最后一批获取的批次的索引,知道将在哪里获取下一批,那将是完美的。

感谢您的帮助!

回答

-1

经过更详细的搜索,我终于找到here我在找什么: 一个可以使用setFetchBatchSizeNSSortDescriptor