From 5685d08bc4e948efdcbb17e49712021935bc8f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zvonimir=20Pavlovi=C4=87?= Date: Thu, 18 Feb 2021 16:04:10 +0100 Subject: [PATCH] fix: images fetched from the photo library were not ordered correctly, so I ordered them by the creation date ascending, so when you take new photo, it would appear as first in fetched photos, and that same photo would be added to selected images --- Source/AssetManager.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/AssetManager.swift b/Source/AssetManager.swift index edb6e52d..01d49768 100644 --- a/Source/AssetManager.swift +++ b/Source/AssetManager.swift @@ -27,10 +27,13 @@ open class AssetManager { public static func fetch(withConfiguration configuration: ImagePickerConfiguration, _ completion: @escaping (_ assets: [PHAsset]) -> Void) { guard PHPhotoLibrary.authorizationStatus() == .authorized else { return } + let options = PHFetchOptions() + options.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)] + DispatchQueue.global(qos: .background).async { let fetchResult = configuration.allowVideoSelection - ? PHAsset.fetchAssets(with: PHFetchOptions()) - : PHAsset.fetchAssets(with: .image, options: PHFetchOptions()) + ? PHAsset.fetchAssets(with: options) + : PHAsset.fetchAssets(with: .image, options: options) if fetchResult.count > 0 { var assets = [PHAsset]()