該方法為刪除系統(tǒng)相冊(cè)的方法,也可以修改刪除為你想刪除的照片均可以. ? 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:@"相冊(cè)名稱(chēng)"])? {
PHFetchResult *assetResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:[PHFetchOptions new]];
if (assetResult.count==0) {
nslog(@"該相冊(cè)為空");
}
[assetResult enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
//獲取相冊(cè)的最后一張照片
[photoarry insertObject:obj atIndex:photoarry.count];
if (idx == [assetResult count] - 1) {
[PHAssetChangeRequest deleteAssets:photoarry];
}
} completionHandler:^(BOOL success, NSError *error) {
if (success) {
nslog(@"清空相冊(cè)成功");
}
NSLog(@"Error: %@", error);
}];
}];
}
}];
}
}];