IOS删除系统照片方法

该方法为删除系统相册的方法,也可以修改删除为你想删除的照片均可以.   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);

}];

}];

}

}];

}

}];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容