UIActivityViewController Gmail Share subject and b

2019-04-18 04:02发布

问题:

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:

With Gmail:

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

回答1:

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;
}