PHAsset的PHFetchOptions与Photos.app的排序顺序相同

kin*_*cac 4 objective-c ios swift photokit

我正在使用新的PHFetchOptions的sortDescriptors从相机胶卷中获取PHAssets.似乎只有两个键可以排序:creationDate和modificationDate,它们都与您在Photos.app中看到的不同.

我错过了什么吗?我们怎样才能让它发挥作用?

McI*_*ale 7

我使用以下代码获取包含"相机胶卷"的智能相册列表:

// get the smart albums
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
for (NSInteger i = 0; i < smartAlbums.count; i++) {
    PHAssetCollection *assetCollection = smartAlbums[i];
    // Then use the following to get the photo images:
    PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:nil];
    }
Run Code Online (Sandbox Code Playgroud)

默认排序顺序是集合中现有的资产顺序,包括"相机胶卷".为选项传递"nil"将获得默认值.您可以对相机胶卷中的图像重新排序,此代码将反映更改.