gpt4 book ai didi

ios - 从自定义相册 PHPhotoLibrary Objective-C 中删除图像

转载 作者:行者123 更新时间:2023-12-01 18:06:05 25 4
gpt4 key购买 nike

在我的应用程序中,我使用了编辑图片并保存在名为“Fab”的图库中的自定义文件夹中。现在有什么可以从文件夹中删除该图像吗?我找到了不同的解决方案,但它们需要 Assets URL。我使用了照片框架,那么如何获取特定图像的 Assets url 以进行删除?

最佳答案

 PHAsset *tempPhasset = [_arrImageForAssetCameraRoll objectAtIndex:index]; // here pass your PHasset that you want to delete .
NSString *localStr=tempPhasset.localIdentifier;
NSRange range = [localStr rangeOfString:@"/"];
NSString *newString = [localStr substringToIndex:range.location];
NSString *appendedString=[NSString stringWithFormat:@"%@%@%@",@"assets-library://asset/asset.JPG?id=",newString,@"&ext=JPG"];
NSLog(@"%@ phasset ",appendedString);
NSURL *deleteurl = [NSURL URLWithString:appendedString];
NSArray *arrDelete = [[NSArray alloc] initWithObjects:deleteurl , nil];
PHFetchResult *asset = [PHAsset fetchAssetsWithALAssetURLs:arrDelete options:nil];

[asset enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(@"%@",[obj class]);
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
BOOL req = [obj canPerformEditOperation:PHAssetEditOperationDelete];
if (req) {
NSLog(@"true");
[PHAssetChangeRequest deleteAssets:@[obj]];
}
} completionHandler:^(BOOL success, NSError *error) {
NSLog(@"Finished Delete asset. %@", (success ? @"Success." : error));
if (success) {
NSLog(@"delete successfully");
}else{
NSLog(@"delete Cancel");

}
}];

任何关于我的代码的查询然后放评论。
快乐编码。

关于ios - 从自定义相册 PHPhotoLibrary Objective-C 中删除图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44132352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com