如何对专辑进行排序与​​Photos.app相同

时间:2016-10-26 20:39:17

标签: ios photokit

我想以与Photos.app相同的方式对相册进行排序。我为PHFetchOptions:{/ p>尝试了所有可能的PHAssetCollection.fetchAssetCollections(with type: subtype:options:)

  • 默认情况下未指定sortDescriptors
  • sortDescriptors包含localizedTitletitlestartDateendDate, estimatedAssetCount`

但没有一个提供与Photos.app。

相同的顺序

1 个答案:

答案 0 :(得分:0)

// get Photos timeline
guard let timelineFetchResult = PHCollectionList.fetchMomentLists(with: .momentListCluster, options: nil).firstObject else { return }

// get Moments seperated by photos' creation date
let momentsFetchResult = PHAssetCollection.fetchMoments(inMomentList: timelineFetchResult, options: nil)

// get photos from every Moment
for index in 0 ..< momentsFetchResult.count {
    let moment = momentsFetchResult[index]
    let assetsFetchResult = PHAsset.fetchAssets(in: moment, options: nil)
    // ...
}