IOS Photos Sampling

I would like to get a fixed batch of images located on an iOS device. I am using the new Photos Framework and I already found this workaround:

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    
}

It works fine, but I first extract all the photos using fetchAssetsWithMediaType, and then select a subset of the result to load the application, which seems pretty heavy ...

I wanted to know if there is a way to directly load a batch of photos in batch mode, rather than retrieve all of them and then repeat. Also, it would be ideal if I could store the indices of the last loaded batch to find out where I would get the next batch.

Thank you for your help!

+4
1

, : setFetchBatchSize NSSortDescriptor.

-1

Source: https://habr.com/ru/post/1655470/


All Articles