How to set a mail Subject in UIActivityViewController?

Femina picture Femina · Jun 10, 2013 · Viewed 38k times · Source

I want to set subject for email sharing in UIActivityViewController and also want to share in Twitter. I know in Twitter if we want to share — we need compress text to 140 chars. I checked many SO solutions, but nothing is working.

Is this issue fixed in latest iOS releases? Any other "working solutions"?

Answer

emreoktem picture emreoktem · Sep 2, 2013

Check below code for the email for setting up your email subject:

UIActivityViewController* avc = [[UIActivityViewController alloc] initWithActivityItems:@[@"Your String to share"]
                                  applicationActivities:nil];
[avc setValue:@"Your email Subject" forKey:@"subject"];

avc.completionHandler = ^(NSString *activityType, BOOL completed) {
    // ...
};

Here the line

[avc setValue:@"Your email Subject" forKey:@"subject"];

Makes the subject as "Your email Subject" if user picks email option in the UIActivityViewController.

I hope it helps...