How to set UIActivityViewController Gmail Share Su

2020-02-07 00:36发布

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.

3条回答
你好瞎i
2楼-- · 2020-02-07 00:46

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.

查看更多
Juvenile、少年°
3楼-- · 2020-02-07 00:54
家丑人穷心不美
4楼-- · 2020-02-07 00:59

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

查看更多
登录 后发表回答