UIActivityViewController - Email and Twitter sharing

anthoprotic picture anthoprotic · Oct 20, 2012 · Viewed 40.9k times · Source

I recently started working with UIActivity to share my app to the world, but I have few problems. First, I didn't find how to set the subject of my email. Is there any way? Second, when I set the body text of my email, there is a extra "enter" (first line of the email is blank and my text starts at the second line). Here's the code:

 NSMutableArray *array = [[NSMutableArray alloc] initWithObjects: @"Test", nil];

    UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
                                   initWithActivityItems:array applicationActivities:nil];

And in the email, it shows that:

"

Test "

Third: is there a way to know which sharing method has been selected? Because I want to include a hashtag in my post when the user shares on twitter, but now it gets integrated in the email also, which obviously doesn't make sense.

Thanks!

Answer

Ajay picture Ajay · Jun 28, 2013

For adding subject to the email using UIActivityViewController on iOS6, this is the best solution that anyone can use.. All you have to do is call the following while initializing UIActivityViewController.

UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
[activityViewController setValue:@"My Subject Text" forKey:@"subject"];

And your UIActivityViewController is populated with a subject.