Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Am I not understanding UIActivityViewController, or does the implementation currently suck?

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!

like image 506
Mason G. Zhwiti Avatar asked Feb 18 '23 16:02

Mason G. Zhwiti


2 Answers

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.)

like image 146
Tricertops Avatar answered Feb 20 '23 06:02

Tricertops


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.

like image 30
Hampus Nilsson Avatar answered Feb 20 '23 07:02

Hampus Nilsson