4
 let activityViewController = UIActivityViewController (activityItems: contentArray, applicationActivities:nil)
        if let popoverController = activityViewController.popoverPresentationController {
            popoverController.sourceView = sender

        }
        self.presentViewController(activityViewController, animated: true, completion: nil)

So basically I want to share the content only through mail and I do not want to show the option of message. Could you help me out with that. Also I want to set the subject of the email through the code

Somu
  • 601
  • 11
  • 22

1 Answers1

4

Just add excludedActivityTypes to remove all the other activity except email

yourActivityViewController.excludedActivityTypes = [ UIActivityTypePostToFacebook, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo, UIActivityTypeMessage, UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo,UIActivityTypePostToTencentWeibo,UIActivityTypeAirDrop]

Add subject

 yourActivityViewController.setValue("Your email Subject" , forKey: "subject") ;

Suggession :- You can also use MFMailComposeViewController to send email

 var picker = MFMailComposeViewController()
    picker.mailComposeDelegate = self
    picker.setSubject(subject.text)
    picker.setMessageBody(body.text, isHTML: true)

    presentViewController(picker, animated: true, completion: nil)

More References :- How do I use UIActivityItemProvider to send an email with attachment with UIActivityViewController?

iOS 8 - Disable iCloud Photo Sharing Activity

Community
  • 1
  • 1
karthikPrabhu Alagu
  • 3,371
  • 1
  • 21
  • 25
  • By using UIActivityController will I be able to add the subject of the email – Somu Sep 04 '15 at 16:07
  • 2
    How to hide the "Notes" in sharing option? – PAC Mar 28 '16 at 10:49
  • This doesn't hide other third party apps (e.g. Whatsapp) – shim Jun 02 '17 at 20:37
  • 1
    Swift 4: `yourActivityViewController.excludedActivityTypes = [ UIActivityType.postToFacebook, UIActivityType.postToTwitter, UIActivityType.postToWeibo, UIActivityType.message, UIActivityType.print, UIActivityType.copyToPasteboard,UIActivityType.assignToContact,UIActivityType.saveToCameraRoll,UIActivityType.addToReadingList, UIActivityType.postToFlickr, UIActivityType.postToVimeo,UIActivityType.postToTencentWeibo,UIActivityType.airDrop]` – Liam Bolling Mar 02 '18 at 15:31