Search code examples
iosswiftuiactivityviewcontrolleruiactivity

UIActivity from UIActivityType


Is there a way to get UIActivity from and an existing UIActivityType?

So I can construct UIActivityViewController like:

let activityViewController = UIActivityViewController(activityItems: [],
   applicationActivities: [MyActivity(),"TypeUIActivity"])

present(activityViewController, animated: true, completion: {})

Solution

  • Reading through the Apple documentation about this and I read:

    Subclassing Notes

    This class must be subclassed before it can be used. The job of an activity object is to act on the data provided to it and to provide some meta information that iOS can display to the user. For more complex services, an activity object can also display a custom user interface and use it to gather additional information from the user. “

    That means you’ll need to create a custom implementation of UIActivity and override its functionality to create the method you wish to use. Like creating a custom implementation of a CollectionViewCell.