[英]How to add image in PHAsset and delete it from photo library?
I am working on an app like hiding photos and I want to move the images to my app so for that I have to import images from photo library and delete that image from library but I cant understand how to work with PHAssets
and where to implement. 我正在开发一个类似隐藏照片的应用程序,我想将图像移到我的应用程序中,因此我必须从照片库导入图像,然后从库中删除该图像,但是我不明白如何使用PHAssets
以及在哪里实现。
I used the UIPickerview to pick the image and then delete it from library please anyone can help me for that 我使用了UIPickerview来选择图像,然后将其从库中删除,任何人都可以帮助我
This the picker where I get image : 这是我得到图像的选择器:
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
And this is for delete but what is asset : 这是用于删除,但资产是什么:
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
[PHAssetChangeRequest deleteAssets:formatWithOrientation];
} completionHandler:^(BOOL success, NSError *error) {
NSLog(@"Finished deleting asset. %@", (success ? @"Success." : error));
}];
Try this code. 试试这个代码。 It's working for me. 它为我工作。
PHFetchResult *asset = [PHAsset fetchAssetsWithALAssetURLs:@“Your asset url” 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”);
}
}];
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.