iosswiftuiactivityviewcontrollerios-sharesheet

UIActivityViewController: "Add Tags" Action


Background

My app supports exporting CSV files using the following code (where CSVFileActivityItemProvider is a UIActivityItemProvider subclass that provides the URL to a CSV file stored in FileManager.default.temporaryDirectory):

func exportCSVFile() {
    let item = CSVFileActivityItemProvider()
    let controller = UIActivityViewController(activityItems: [item], applicationActivities: nil)
    present(controller, animated: true)
}

The code works perfectly except for the "Add Tags" action (which may be added if Apple's Files app is installed?). When tapped, the "Add Tags" controller is presented and then immediately dismissed.

Add Tags Image

Questions

  1. How do I handle the "Add Tags" action in UIActivityViewController?
  2. Can I exclude the "Add Tags" action (as Apple has done in Numbers v11.1 on iOS when you export a document to TSV)?

Solution

  • It turns out that simply using a TSV file instead of a CSV file will automatically exclude the "Add Tags" action (which explains what I was seeing in Numbers). This is a viable workaround for me. In cases where a TSV file is not desirable, it is possible to at least detect the "Add Tags" activity by using UIActivityViewController.CompletionWithItemsHandler.