29

I am sharing Some content via UIActivityController.

It is working fine for other Options.

I am able to get subject and body in Default Mail App.

But when I use to share the content with gmail then my Subject of the mail is gone and I am getting Body content in Gmail Subject's section:

Here is my code:

    NSString *body = @"I am Body";
NSString *tagLine = @"I am Subject";

   NSArray *objectToShare = [NSArray arrayWithObjects:body, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectToShare applicationActivities:nil];

[activityVC setValue:tagLine forKey:@"subject"];

NSArray *excludeActivities = @[UIActivityTypeAirDrop,
                               UIActivityTypePrint,
                               UIActivityTypeAssignToContact,
                               UIActivityTypeSaveToCameraRoll,
                               UIActivityTypeAddToReadingList,
                               UIActivityTypePostToVimeo];

activityVC.excludedActivityTypes = excludeActivities;

[self presentViewController:activityVC animated:YES completion:nil];

For better Picture Here is the screenshot:

With Default App:

enter image description here

With Gmail: enter image description here

I also tried different answers on SO. But none of them works.

Rahul
  • 5,594
  • 7
  • 38
  • 92
  • 1
    Got any solution for this issue, i am also getting same issue ? – San007 Apr 18 '16 at 11:49
  • @San007 no bro. Not get any solution. – Rahul Apr 24 '16 at 13:59
  • @RahulMishra Any new here ? – Yossi May 29 '16 at 11:37
  • @Yossi No Yossi Didn't found any solution :( – Rahul May 29 '16 at 13:46
  • @RahulMishra It's looks like Gmail's bug. I implemented UIActivityItemProvider that using UIActivityItemSource protocol, which is a better way to handle it, and still it not helps – Yossi May 29 '16 at 14:41
  • More than 2 years and still the same issue with Gmail and Google Inbox. Any news out there? – Felipe Plets Jul 06 '16 at 18:36
  • @FelipePlets no news about this bug. Still struggling to get a finest solution. – Rahul Jul 07 '16 at 05:19
  • 1
    I am seeing this same issue. It's 2017 already, no solution yet? – cavalleydude Jan 11 '17 at 21:51
  • 1
    Created and issue in google product forums related to this ticket, please upvote: https://productforums.google.com/forum/#!topic/gmail/UJJx4BcRJiU;context-place=forum/gmail – brisky Jun 12 '17 at 07:46
  • @brisky upvoted... lets c when this is fixed :) – Rahul Jun 12 '17 at 07:49
  • It's almost 2018, no solution yet? :) – Glenn Posadas Dec 12 '17 at 17:57
  • I've got this issue as well. The entire message body is showing up in the Subject line. – Santosh Jan 25 '18 at 11:04
  • @Santosh Unfortunatley there is not solution for this yet. – Rahul Jan 25 '18 at 11:25
  • this is common problem with all 3rd party email clients I know (Google, Yahoo, Outlook). There is nothing you can do. – Juraj Antas Mar 21 '18 at 12:10
  • 2
    It is still not fixed in 2018. and there's no way we can stop sharing to email clients. – Hemang Dec 01 '18 at 06:46
  • Hi guys, I have open an issue on Gmail's official discussion forum. If you want to fix this let's show your support by commenting / or you may create another issue. https://productforums.google.com/forum/#!topic/gmail/9JRqN0rVxYo;context-place=forum/gmail – Hemang Dec 01 '18 at 08:20
  • Dude! This guy found how they do it on Reddit for iOS (and I noticed that Slack also does it) https://stackoverflow.com/a/51451433/1272263 They add a lot of empty spaces in the beginning of the body text! Here is a screenshot of it. Mail app on the left and Gmail on the right: https://i.stack.imgur.com/ThsY1.jpg Still a hack but it works – Carlos Zinato Jun 18 '19 at 12:32

1 Answers1

5

At the time of writing this, Google doesn't allow setting the subject of email. People have reported it as a bug multiple times, and it seems this feature is still not supported.

Looking at other Google-owned products, and trying to share some contents via Gmail, you will see that the Gmail shared activity doesn't have the subject (e.g Google Chrome), or it's the same as the email's body (Google Translator), while if you share them to the normal app it appears that some of them have a subject. So even Google products have the same behaviour.

If you use a breakpoint inside the subjectForActivityType function you will realise that the Gmail activity won't hit the breakpoint while default mail and other activities will attempt to read the subject.

@implementation EmailItemProvider

- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
    return _body;
}

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
    return _body;
}

- (NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType {
    return _subject;
}
Darshan Rivka Whittle
  • 32,989
  • 7
  • 91
  • 109
Amir.n3t
  • 2,859
  • 3
  • 21
  • 28
  • I know that everyone have reported it as a bug but I've saw today that Reddit managed to take the "Subject" out in their app. I've posted more information here: https://stackoverflow.com/a/56646569/1272263 – Carlos Zinato Jun 18 '19 at 10:03