4

I'm trying to move my app to use UIActivityViewController, rather than UIActionSheet, so that I get the fancy graphical sharing buttons rather than the textual buttons. (My app is targeted at iOS 6 only.)

After trying to work with it for a couple nights, it seems either I am totally misunderstanding how to use it, or the current implementation by Apple is terrible:

  • You can't specify a different message for different services. If I want something that will work across: Mail, Facebook, Messages AND Twitter, it's going to need to be 140 characters max, to work on Twitter. Is there a way to set custom content for each type of activity?

  • There appears to be no way to set a subject line or recipient for Mail messages. I've read the docs, they make it sound like this might be possible with an NSURL that uses the mailto: protocol, but in my tests, those URLs just get shoved into the message body. Is there actually a way to set the subject line and optionally, the recipients?

  • If I want to work around these shortcomings, and do my own custom activities by subclassing UIActivity, I have to use a custom image/icon. Therefore, I can't mimic the Mail activity with Apple's official icon, and e.g. implement my own custom activity backend that actually lets me set the subject line, recipients, custom body, etc. Am I wrong, is there a way to use Apple's service icons, but have a chance to customize the behavior? (The only callback I see is one that runs AFTER the activity has been completed, right?)

I hope I'm wrong!

Mason G. Zhwiti
  • 6,444
  • 11
  • 61
  • 97

2 Answers2

7

Is there a way to set custom content for each type of activity?

Yes, I guess you should subclass UIActivityItemProvider and override method –activityViewController:itemForActivityType: with your logic (e.g. trim string to 140 chars for Twitter).
Then pass an instance of this class to -[UIActivityViewController initWithActivityItems:applicationActivities:].


Is there actually a way to set the subject line and optionally, the recipients?

You are right, the mailto scheme should be able to set these fields. If it is not working, I consider this as bug. (Didn't try this myself, but I will give it a check.)


Is there a way to use Apple's service icons, but have a chance to customize the behavior?

I think you can't do this. (Unless you want to hack those system activities.)

Tricertops
  • 8,492
  • 1
  • 39
  • 41
  • Confirming all this. I'm using UIActivityItemProvider subclass for exactly that purpose, and it works fine. And there is indeed a mailto: bug; the URL ends up appearing in the body text. Phooey. – JLundell Feb 14 '13 at 17:23
  • Unfortunately it doesn't sound like UIActivityItemProvider is custom enough, as it's not just a matter of trimming text for twitter, but of forming a custom tweet that has different text entirely. I appreciate the feedback! – Mason G. Zhwiti Feb 14 '13 at 23:58
  • You can put there anything you want. If you want _Loprem Ipsum_ for Twitter and _Bible_ for Facebook, you can do it. – Tricertops Feb 15 '13 at 11:19
  • Yep. mailto bug - http://stackoverflow.com/questions/12623260/how-do-i-set-recipients-for-uiactivityviewcontroller-in-ios-6?rq=1 – Joshua Dance May 14 '13 at 20:47
  • Trimming the string was just an example - if you subclass UIActivityItemProvider, you can return any text at all for the tweet. – Bill Nov 05 '13 at 13:44
1

You are better off using a custom component that behaves like UIAcitvityController as it is quite limited, as you noted.

This is one example: https://github.com/hjnilsson/REActivityViewController , I just forked it from https://github.com/romaonthego/REActivityViewController to allow you to set the email subject field.

Hampus Nilsson
  • 6,692
  • 1
  • 25
  • 29