Last active
January 12, 2021 05:09
-
-
Save mwpcheung/f94bdfafce708fc2345cb63c3d4bcf5f to your computer and use it in GitHub Desktop.
iOS list/delete Recently Deleted photo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void listRecentlyDeleted() | |
{ | |
// iOS list system recently deleted photo and delete them | |
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { | |
PHFetchOptions* opt = [[PHFetchOptions alloc]init]; | |
opt.includeAllBurstAssets = YES; | |
opt.includeHiddenAssets = YES; | |
opt.includeAssetSourceTypes = YES; | |
PHFetchResult *result = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:(PHAssetCollectionSubtype)1000000201 options:opt]; | |
NSMutableArray* items = [[NSMutableArray alloc]init]; | |
for (PHAssetCollection*collection in result){ | |
PHFetchOptions *options = [[PHFetchOptions alloc] init]; | |
options.wantsIncrementalChangeDetails = YES; | |
options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d",PHAssetMediaTypeImage]; | |
PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:options]; | |
NSLog(@"album title %@ album photo count %ld", collection.localizedTitle, fetchResult.count); | |
for (PHAsset* asset in fetchResult){ | |
[items addObject:asset]; | |
} | |
} | |
NSLog(@"here we get the system recently deleted photos"); | |
[PHPhotoLibrary.sharedPhotoLibrary performChanges:^(){ | |
NSLog(@"to delete items %ld", items.count); | |
[PHAssetChangeRequest performSelector:@selector(expungeAssets:) withObject:items]; | |
} completionHandler:^(BOOL success, NSError* error){ | |
NSLog(@"delete system image asset finished" | |
}]; | |
}]; | |
} |
Author
mwpcheung
commented
Dec 17, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment