Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Add option to present assets sorted by creation date. #187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions QBImagePicker/QBAssetsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ - (void)updateFetchRequest
if (self.assetCollection) {
PHFetchOptions *options = [PHFetchOptions new];

if (self.imagePickerController.sortOrder == ByLatestAsset) {
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
}

switch (self.imagePickerController.mediaType) {
case QBImagePickerMediaTypeImage:
options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %ld", PHAssetMediaTypeImage];
Expand Down
6 changes: 6 additions & 0 deletions QBImagePicker/QBImagePickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ typedef NS_ENUM(NSUInteger, QBImagePickerMediaType) {
QBImagePickerMediaTypeVideo
};

typedef enum {
ByLatestAsset, ByOldestAsset
} Sort;

@interface QBImagePickerController : UIViewController

@property (nonatomic, weak) id<QBImagePickerControllerDelegate> delegate;
Expand All @@ -48,4 +52,6 @@ typedef NS_ENUM(NSUInteger, QBImagePickerMediaType) {
@property (nonatomic, assign) NSUInteger numberOfColumnsInPortrait;
@property (nonatomic, assign) NSUInteger numberOfColumnsInLandscape;

@property (nonatomic, assign) Sort sortOrder;

@end
1 change: 1 addition & 0 deletions QBImagePicker/QBImagePickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ - (instancetype)init
self.minimumNumberOfSelection = 1;
self.numberOfColumnsInPortrait = 4;
self.numberOfColumnsInLandscape = 7;
self.sortOrder = ByOldestAsset;

_selectedAssets = [NSMutableOrderedSet orderedSet];

Expand Down
2 changes: 2 additions & 0 deletions QBImagePickerDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSPhotoLibraryUsageDescription</key>
<string>Application requires Photos access to obtain your photos and videos</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions QBImagePickerDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
imagePickerController.mediaType = QBImagePickerMediaTypeAny;
imagePickerController.allowsMultipleSelection = (indexPath.section == 1);
imagePickerController.showsNumberOfSelectedAssets = YES;
imagePickerController.sortOrder = ByLatestAsset;

if (indexPath.section == 1) {
switch (indexPath.row) {
Expand Down