How to know if an PHAssetCollection is the recently deleted collection?

给你一囗甜甜゛ 提交于 2019-12-09 19:08:02

问题


There is a subtype for the recently added collection: PHAssetCollectionSubtypeSmartAlbumRecentlyAdded. However there is no assetCollectionSubtype that would identify the "Recently Deleted" collection.

This is the description of the "Recently Deleted" collection in my case: (iOS 8.1.3): DF876BFD-...-C97F4628467C/L0/040 Recently Deleted assetCollectionType=2/1000000201

This indicates it is of type PHAssetCollectionTypeSmartAlbum. But what the heck is subtype 1000000201?

201 should be PHAssetCollectionSubtypeSmartAlbumPanoramas according to the docs.

Can the magic number 1000000201 be trusted to never change? Probably not.

However, this is how you can retrieve the recently deleted collection:

PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:1000000201 options:nil];

There is a major difference in this particular smart album: the PHAssets can not be deleted (again), because this is the trash. So it'd be essential to know if a delete option should be presented to the user.

Does anyone have an idea?


回答1:


Regarding picking out the "Recently Deleted" collection, here's a workaround.

PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum
                                                                      subtype:PHAssetCollectionSubtypeAlbumRegular
                                                                      options:nil];

__block PHAssetCollection *recentlyDeletedCollection;
[smartAlbums enumerateObjectsUsingBlock:^(PHAssetCollection *smartAlbum, NSUInteger idx, BOOL *stop) {
    if ([smartAlbum.localizedTitle isEqualToString:@"Recently Deleted"]) {
        NSLog(@"Recently Deleted album is at %ld", idx);
        recentlyDeletedCollection = smartAlbums[idx];
    }
}];


来源:https://stackoverflow.com/questions/28269867/how-to-know-if-an-phassetcollection-is-the-recently-deleted-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!