Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Providing different shared items for each activity with UIActivityViewController

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
like image 328
cannyboy Avatar asked Nov 19 '25 01:11

cannyboy


1 Answers

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/

like image 184
Andris Zalitis Avatar answered Nov 21 '25 16:11

Andris Zalitis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!