How to set UIActivityViewController Gmail Share Subject different than body

拟墨画扇 提交于 2019-12-04 03:04:08

问题


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.


回答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:


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.




回答3:


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.

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:



来源:https://stackoverflow.com/questions/30350465/how-to-set-uiactivityviewcontroller-gmail-share-subject-different-than-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!