该方法为删除系统相册的方法,也可以修改删除为你想删除的照片均可以. NSMutableArray *photoarry=[[NSMutableArray alloc]init];
PHFetchResult *collectonResuts = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:[PHFetchOptions new]] ;
[collectonResuts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
PHAssetCollection *assetCollection = obj;
NSLog(@"%@",assetCollection.localizedTitle);
if ([assetCollection.localizedTitle isEqualToString:@"相册名称"]) {
PHFetchResult *assetResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:[PHFetchOptions new]];
if (assetResult.count==0) {
nslog(@"该相册为空");
}
[assetResult enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
//获取相册的最后一张照片
[photoarry insertObject:obj atIndex:photoarry.count];
if (idx == [assetResult count] - 1) {
[PHAssetChangeRequest deleteAssets:photoarry];
}
} completionHandler:^(BOOL success, NSError *error) {
if (success) {
nslog(@"清空相册成功");
}
NSLog(@"Error: %@", error);
}];
}];
}
}];
}
}];