我使用此代码删除图片选择器选择的照片应用中的图片。 选择多个图像后,它将返回assetArray中的所选图像。 现在我想删除那些图像,但它会给出错误"对象必须是PHAsset类型"
- (void)assetsPickerController:(GMImagePickerController *)picker didFinishPickingAssets:(NSArray *)assetArray
{
[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];
NSLog(@"===%@===",assetArray);
void (^completionHandler)(BOOL, NSError *) = ^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
[[self navigationController] popViewControllerAnimated:YES];
});
} else {
NSLog(@"Error: %@", error);
}
};
// Delete asset from library
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
[PHAssetChangeRequest deleteAssets:@[assetArray]];
} completionHandler:completionHandler];
NSLog(@"GMImagePicker: User ended picking assets. Number of selected items is: %lu", (unsigned long)assetArray.count);
}
答案 0 :(得分:0)
你创建了一个数组数组。只需这样:
[PHAssetChangeRequest deleteAssets:assetArray];