11

I am using Gmail Share Extension from Google. I am providing implementation of:

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType; - (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController; - (NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType; 

For Mail client (from Apple) it goes into delegate method below but Gmail

- (NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType; 

Instead it shows subject same as body text. I am wondering how can I set subject different than body text for Gmail Share option.

12
  • I had the exact same problem a few hours ago, a mystery indeed :| Commented May 20, 2015 at 13:03
  • Have you try like that? UIActivityViewController* activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[@"Your body String to share"] applicationActivities:nil]; [activityViewController setValue:@"Your email Subject" forKey:@"subject"]; activityViewController.completionHandler = ^(NSString *activityType, BOOL completed) { // ... }; Commented May 20, 2015 at 13:07
  • @Shai I am having so many issues with Gmail sharing extension. I found hack for few but few are still mystery :( Commented May 20, 2015 at 13:18
  • 1
    The issue still exists Commented Jun 6, 2018 at 7:52
  • 2
    It's 2020 the issue still exists. Commented Feb 23, 2020 at 10:55

3 Answers 3

2

The solutions is pretty simple - need pass NSUrl to the list of activity items.

Here is a sample on Swift:

ActivityViewController(activityItems: [URL(string: "https://www.apple.com")!]) 

Here is for Xamarin:

 public override NSObject GetItemForActivity(UIActivityViewController activityViewController, NSString activityType) { NSObject item = null; if (activityType == UIActivityType.Mail) { item = PlaceholderItem; } else if (activityType == new NSString(_gmailActivityId)) { item = NSUrl.FromString("https://www.apple.com"); } else if (activityType == new NSString(_sparkActivityId)) { item = PlaceholderItem; } return item ?? base.GetItemForActivity(activityViewController, activityType); } 

From that perspective, if you will pass any string items - they will be copied. App Store, Facebook and others are passing URLs or URLs+Images - which looks like also are handling somehow by Gmail client.

Sign up to request clarification or add additional context in comments.

Comments

1

This is a GMail app issue

A bug report was filled on 12/06/2017

https://productforums.google.com/forum/#!topic/gmail/UJJx4BcRJiU;context-place=forum/gmail

Another discussion about the issue:

https://github.com/BranchMetrics/ios-branch-deep-linking/issues/789

2 Comments

Is this really still a bug on Gmail's part? Seems like they've had some time to fix.
It seems they don't care too much about it
1

I've been fighting this for a couple of days already and all I could find was marked as a known bug but browsing Reddit this morning just for fun I see that they successfully managed to have at least an empty Subject field, the question is, how? Anyone from Reddit maybe? If you share the same content on the native mail app it fills the subject field up with the title of the post which is the expected behavior.reddit

UPDATE: 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! Took a screenshot comparing the original Mail (on the left) body and Gmail (on the right) one: solution

2 Comments

I pad the text with 2000 space characters at the beginning but I still don't get a clean subject field. Is there a special character I should be using?
I had the same =( I've tried with a lot of special characters like \n or \r and I could not achieve the desired result...I hope someone can help us on that...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.