Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To share a file URL between two instances of your app using UIActivityViewController, you will need to follow these steps:

  1. Create an instance of UIActivityViewController with the file URL as the item to share:
let fileURL = URL(string: "file:///path/to/your/file")!
let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
  1. Set the excludedActivityTypes property of the activityViewController to remove any activities that you don't want to show:
activityViewController.excludedActivityTypes = [.airDrop, .addToReadingList]
  1. Present the activityViewController from the view controller where you want to share the file URL:
present(activityViewController, animated: true, completion: nil)
  1. When the user selects the instance of your app from the activityViewController, handle the file URL in the appropriate way in the receiving view controller.
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    // handle the file URL here
    return true
}

By following these steps, you can share a file URL between two instances of your app using UIActivityViewController.