9

Foe setting subject of share, overriding

   func activityViewController(activityViewController: UIActivityViewController, subjectForActivityType activityType: String?) -> String {
          return "mySubject"
    }

not working for outlook app, while sharing. this method not being called for outlook, works for other apps like mail, gmail etc.

Found that some app like Yelp, Apple maps, Google Maps able to set subject in outlook. How'd one achieve it?

BaSha
  • 2,356
  • 3
  • 21
  • 38

1 Answers1

4

I believe I figured out how this was made to work in those apps. I observed the same behavior in my own app where func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivityType?) -> String is not being called when choosing the Outlook app. However, I noted the CNN app, as an example, was properly creating a subject line.

The answer it seems is to make the first line of the body text be what you wish the subject to be. I had an asset I was attaching with a URL and so the subject was inserting the URL which I didn't want. However, when I made the subject I did want, the first line of the body in the email, it did then populate the email's subject in Outlook correctly.

So this isn't ideal and certainly the appropriate protocol function should be called, but this does appear to be how others have gotten around what we otherwise cannot fix for Apple or Microsoft.

C6Silver
  • 3,127
  • 2
  • 21
  • 49
  • Not able to get what you saying, can you explain it a bit more clearly. Thanks in advance. – Pavan Feb 28 '19 at 07:28
  • The outlook app is taking the first line of the body text and making it the subject. So making whatever you want as the subject, the first line of the body text, is how you can get the subject to populate with what you need. Again this is obviously not ideal but rather a work-around. – C6Silver Mar 01 '19 at 17:58
  • I saw the behavior of picking Subject from Body in Gmail App, but Outlook app is still being empty both in subject and body. I have downloaded latest Outlook App onto my device. – Pavan Mar 04 '19 at 05:35
  • For some reason Outlook behaving differently on iOS 11 and iOS 12. in iOS 12 it is setting email body and Subject is being empty. – Pavan Mar 04 '19 at 06:59
  • That's a brilliant idea and I saw that Reddit and Slack are doing the same for the Gmail sharing activity! Thanks for it! – Carlos Zinato Jun 18 '19 at 12:16
  • @C6Silver can I ask something? How do you add an empty line at the beginning of the body string so the subject is clear? I couldn't make it with "\n" or "\r" – Carlos Zinato Jun 19 '19 at 08:11
  • @CarlosZinato did ever figure out how to set the subject with an empty line? If so, please share. – user979331 Dec 14 '19 at 07:30
  • @user979331 I came across the same issue and it is still not fixed... this is what i added in the itemForActivityType for Gmail return "Subject \n Bodytext.." then only the Subject appears and body is empty. – Vario Mar 07 '21 at 15:23
  • This works partly. It add the first line of the body as the subject BUT the subject text still remains as part of the body, which doesn't make sense. Most, if not all cases, subject and body have different texts. Is there any way to have different text for subject and body (subject not being part of body) using this workaround? – user121095 Jun 05 '23 at 11:39