简体   繁体   English

如何根据添加到画廊的日期对 Swift 中的照片进行排序

[英]How to sort photos in Swift based on date added to gallery

My app has a requirement where photos are loaded from iPhone gallery and listed in the app.我的应用程序要求从 iPhone 画廊加载照片并在应用程序中列出。 Currently the sort order is based on PHAsset creationDate property.目前排序顺序基于PHAsset creationDate属性。 I would like to know how we can sort the assets based on the date added as how we see in All photos on iPhone.我想知道我们如何根据添加的日期对资产进行排序,就像我们在 iPhone 上的所有照片中看到的那样。

I could see that PHAsset properties creationDate , modificationDate and other dates(listed below) from PhAsset metadata are the same, which is the date taken of the photo.我可以看到PhAsset元数据中的PHAsset属性creationDatemodificationDate和其他日期(如下所列)是相同的,即拍摄照片的日期。

  1. DateTime约会时间
  2. DateTimeDigitized日期时间数字化
  3. DateTimeOriginal日期时间原始

Is there a way to get the date added for a PHAsset ?有没有办法获得为PHAsset添加的日期?

You should check out PHFetchOptions you would end up doing something like this你应该检查PHFetchOptions你最终会做这样的事情

let fetchOptions = PHFetchOptions()
let sortOrder = [NSSortDescriptor(key: "creationDate", ascending: false)]
fetchOptions.sortDescriptors = sortOrder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM