问题
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 PHAsset
s 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