PHFetchResult *collectonResuts = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:[PHFetchOptions new]] ;
[collectonResuts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
PHAssetCollection *assetCollection = obj;
if (assetCollection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumUserLibrary) {
PHFetchOptions *options = [PHFetchOptions new];
options.fetchLimit = 1;
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
PHFetchResult *assetResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:options];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
//获取相册的最后一张照片
if (assetResult.firstObject) {
[PHAssetChangeRequest deleteAssets:@[assetResult.firstObject]];
}
} completionHandler:^(BOOL success, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
}];
网友评论