So i'm developing an app to let user select a few photos in the system Photo Library then using the Action Extension via the share sheet to delete some of those photos.
I was using extensionContext.inputItems
to get the URLs of the selected photos:
let extensionItems = (self.extensionContext!.inputItems as! [NSExtensionItem]).first!
let attachments = extensionItems.attachments! as! [NSItemProvider]
for provider in attachments {
provider.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil) {
(imageURL, error) in
...
...
...
}
}
Then i was using PHAssetChangeRequest.deleteAssets
to delete photos by it's URL
PHPhotoLibrary.shared().performChanges({
let imageAssetToDelete = PHAsset.fetchAssets(withALAssetURLs: imageURLs, options: nil)
PHAssetChangeRequest.deleteAssets(imageAssetToDelete)
}, completionHandler: {success, error in
if success {
print("success")
} else {
print(error!)
}
})
The "success" was printed to the console but the photo deletion doesn't requested (that delete photo alert like this doesn't shown)
So i inspected the variable imageAssetToDelete
but it prints:
<PHFetchResult: 0x28188b200> count=0
the PHFetchResult
has no items.
Which part went wrong?