Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController Gmail Share unable to set subject field in swift

I am using UIActivityViewController to share but on gmail when I set its subject specifically it does not set. Any help please.

let eventURL = eventShare[sender.tag]
let eventTitleText = eventTitle[sender.tag]
let contentDescription = eventDescription[sender.tag]

let contentURL:NSURL = NSURL(string:eventURL)!

let activityViewController : UIActivityViewController = UIActivityViewController(activityItems: [contentDescription, contentURL],applicationActivities: nil)

activityViewController.setValue("Our Buzz - \(eventTitleText)", forKey: "Subject")
activityViewController.popoverPresentationController?.sourceView = self.view
self.presentViewController(activityViewController, animated: true, completion: nil)
like image 556
Muhammad Fasi Avatar asked Jun 01 '16 13:06

Muhammad Fasi


2 Answers

Try "subject" instead of "Subject" (lower case)

like image 112
Sonny Saluja Avatar answered Oct 04 '22 03:10

Sonny Saluja


This seems to be a bug with the Gmail/Inbox apps. Using "Subject" as the key works correctly for Apple's Mail app but not for Gmail/Inbox. Other keys which also do not work include "subject", "title", "Title".

Another thing to be aware of is that the subject for Gmail/Inbox will include all the items in activityItems that you pass.

Since "Subject" sets the subject, people might be inclined to think that "Body" or some variant may work; but that results in a crash.

like image 24
EndersJeesh Avatar answered Oct 04 '22 04:10

EndersJeesh