Done Button behavior in UIActivityViewController Markup tool

I am trying to make the UIActivityViewController Markup tool work in my app using the code below (iOS 13/ iPad only):

@IBAction func actionButtonPressed(_ sender: UIBarButtonItem) { 
let items = [<URL of a pdf file>]
let avc = UIActivityViewController(activityItems: items as [Any], applicationActivities: nil)
avc.modalPresentationStyle = UIModalPresentationStyle.popover
avc.popoverPresentationController?.barButtonItem = sender
avc.completionWithItemsHandler = { (type,completed,items,error) in
if type == .markupAsPDF {
if completed {
print("markup completed")
} else {
print("markup not completed")
}
}
}
self.present(avc, animated: true, completion: nil) }

The pdf file is in my app iCloud container.


Everything is fine until I press the Done button (top left corner). I am then presented with a popup with two choices: "Save File To..." and "Delete PDF"


1) Those two options don't make any sense for my app. What I would really want is "Save" and "Cancel". Or simply no options and just save the changes.


2) Although I don't care about the "Save File To..." option, it seems to work as expected.


3) The second and last option is "Delete PDF" which seems scary. One would think that the pdf file being annotated will be deleted. Not what I want. But it turns out that choosing "Delete PDF" simply saves the annotations in the original pdf file. This is completely confusing (and the returned "completed" flag is false....)


I noticed that the iOS Files app also allows pdf files to be annotated but in the Files App case when the user presses the "Done" button, annotations are simply saved without the "Save File To..."/"Delete PDF" options. That would be a lot more preferable for my app.


I tried several things (e.g pass a NSData instead of URL, copy the file to the local Documents folder, etc...) no luck.


Anybody knows how to implement the Files app behavior for the Done button?


The current behavior is completely confusing and I would have to simply remove the markup activity from the UIActivityViewController if I can't find a solution.


Thanks

Replies

Were you able to find an answer to this? My app also needs this functionality of the "Done" button being pressed without the "Save File To..."/"Delete PDF" that pops up. Hit the same wall.