Pregunta

How would I provide a completely different set of data to each service in with a UIActivityViewController?

For instance:

  • MESSAGE an image of a hat, and the text "This is a hat"
  • FACEBOOK a url - http://www.google.com , and the text "Find a hat here"
  • EMAIL an image of a cat, and the url lolcats.com
  • CUSTOM SERVICE an image
¿Fue útil?

Solución

You can provide different data for different activities by creating a class that adopts UIActivityItemSource protocol and implements the method:

-(id)activityViewController:itemForActivityType:

Then pass the object of your custom class to your UIActivityViewController in activityItems array with a call -(id)initWithActivityItems:applicationActivities:

From documentation of this method:

... Instead of actual data objects, the objects in this array can be objects that adopt the UIActivityItemSource protocol, such as UIActivityItemProvider objects. ...

Here is a tutorial about how to do that: https://www.albertopasca.it/whiletrue/objective-c-custom-uiactivityviewcontroller-icons-and-text/

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top