[Interest] iOS: HowTo get Photos from assets-library sorted by lastModified ?

ekke ekke at ekkes-corner.org
Sat Jun 30 08:51:31 CEST 2018


it's easy to get the QDir("assets-library://") containing all the Photos:

QDir theDir = QDir("assets-library://");
QFileInfoList entryList = theDir.entryInfoList();
for (int i = 0; i < entryList.size(); ++i) {
    QFileInfo fileInfo = entryList.at(i);
    // fileInfo.filePath() is something like this:
    //
"assets-library://asset/asset.JPG?id=01DC0CE7-0A57-4B42-BF2E-9A5719D04E1D&ext=JPG"


So getting access to the Photos and displaying them as Image is no problem

unfortunately the files are not sorted and because
`fileInfo.lastModified()` and `fileInfo.created()` are empty I cannot
sort them.

I know that there's a way to use the native iOS ImagePicker from Qt:

import Qt.labs.platform 1.0
// hint: also tried FileDialog from QtQuick.Dialogs 1.2
// but J-P told me QtQuick.Dialogs FileDialog is a 'Monster' - I should
use from labs.platform
FileDialog {
    fileMode: FileDialog.OpenFiles
    property var standardPicturesLocations:
StandardPaths.standardLocations(StandardPaths.PicturesLocation)
    folder: standardPicturesLocations[standardPicturesLocations.length - 1]
}

The native Picker displays Phortos sorted by Date, but only allows to
pick single files.

https://bugreports.qt.io/browse/QTBUG-67874

I need multi-selection of files, so I created a GridView to preview
thumbnails and to select one or more Photos. This works fine but users
are complaining that the Photos are not sorted.

Seems I need some iOS native code to get a sorted Array of Pathes to
Photos from assets-library.
Looked at StackOverFlow and found:

https://stackoverflow.com/questions/7977664/sort-files-by-creation-date-ios#
don't know if this would work with assets (Photos)

--
https://stackoverflow.com/questions/30602830/phfetchresult-get-all-photos-and-sort-by-date-inconsistent/30603715
seems this does what I want, but how to implement that in a way to get
an array of pathes for the Photos

With my less or zero knowledge of native iOS / Obj-C development I don't
understand HowTo get this working for Qt.

Anyone has solved this or any ideas HowTo get the list of Photos from
iOS sorted ?

(will provide the solution together with my nearly ready-to-go QML
Camera App for Android / iOS)

THANKS


ekke




More information about the Interest mailing list