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.

sanjana
  • 3,034
  • 2
  • 25
  • 31
  • I had the exact same problem a few hours ago, a mystery indeed :| – Shai May 20 '15 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) { // ... }; – aBilal17 May 20 '15 at 13:07
  • @Shai I am having so many issues with Gmail sharing extension. I found hack for few but few are still mystery :( – sanjana May 20 '15 at 13:18
  • @aBilal17 Yes I tried adding subject using [activityViewController setValue:@"Your email Subject" forKey:@"subject"] but it doesn't work :( Also its not documented api so even if it works there are chances of rejection but it doesnt :/ – sanjana May 20 '15 at 13:30
  • did you solve this problem..I am also facing this issue...Can't find any solution – Rahul Dec 14 '15 at 09:50
  • @RahulMishra I didn't get any solution sadly :( – sanjana Dec 15 '15 at 08:49
  • thnx for response @sanjana – Rahul Dec 15 '15 at 10:11
  • according with different posts, this is a gmail bug http://stackoverflow.com/questions/34264751/uiactivityviewcontroller-gmail-share-subject-and-body-going-same – desgs1990 Sep 23 '16 at 20:31
  • No solution until now. It's almost 2018. :D – Glenn Posadas Dec 12 '17 at 17:58
  • @Glenn I don't have any hope now xD – sanjana Dec 14 '17 at 00:30
  • 1
    The issue still exists – melbic Jun 06 '18 at 07:52
  • 2
    It's 2020 the issue still exists. – M Reza Feb 23 '20 at 10:55

3 Answers3

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.

bkmza
  • 241
  • 2
  • 8
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

batsansierra
  • 315
  • 1
  • 12
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

Carlos Zinato
  • 591
  • 7
  • 19
  • 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? – Danilo Campos Jun 24 '19 at 20:24
  • 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... – Carlos Zinato Jun 25 '19 at 11:44