Ask Your Question
4

How can I share a file URL between two instances of myApp using UIActivityViewController?

asked 2022-10-14 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-05-26 03:00:00 +0000

lalupa gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-10-14 11:00:00 +0000

Seen: 8 times

Last updated: May 26 '22