Perform action once UIActivityViewController has completed item action

I use UIActivityViewController to airDrop pdfFile (pdfURL) from iPhone to iMac.

Works well, file is airDropped.

        let activityVC = UIActivityViewController(activityItems: [pdfURL], applicationActivities: nil)  
        present(activityVC, animated: true, completion: nil)

I want to customise it:

  • limit services to AIrDrop and mail

How can I exclude such services as WhatsApp, Notes… ?

  • perform some action once the file has completed airDrop or once cancelled.

I tried to implement with completionWithItemsHandler:

        activityVC.completionWithItemsHandler = { (activity, success, items, error) in
            print("Completed")
        }

This doesn't work, print is not executed.

My ultimate goal is to close the activityVC automatically once action was completed, without need to tap close button.

Should I define some content for applicationActivities ?

In fact, in case of AirDrop, the print in

        activityVC.completionWithItemsHandler = { (activity, success, items, error) in
            print("Completed")
        }

is executed, but only after closing the UIActivityView. And not after the airdrop has completed, as I expect.

But if I email or message, it is executed as soon as sent. And UIActivityViewController closes automatically.

So, I'm missing something here when using AirDrop…

Doc for UIActivityViewController states:

It is your responsibility to present and dismiss the view controller using the appropriate means for the given device idiom. On iPad, you must present the view controller in a popover. On other devices, you must present it modally.

Should I understand that there is no way to get it done automatically ?

Perform action once UIActivityViewController has completed item action
 
 
Q