I use UIActivityViewController to share data.
My code:
dispatch_async(dispatch_get_main_queue()) { () -> Void in
let activityViewController : UIActivityViewController = UIActivityViewController(
activityItems: [text!], applicationActivities: nil)
// This line remove the arrow of the popover to show in iPad
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection()
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)
// Anything you want to exclude
activityViewController.excludedActivityTypes = [
UIActivityTypePostToWeibo,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo
]
self.presentViewController(activityViewController, animated: true, completion: nil)
}
I can show SMS, email, and notes, and I can add body text in SMS, email, and notes. But I have a question for email: I only add the body text in the email, but I also want to add a subject for the email. How can I do that?
Just set value of subject to your title like this:
activityViewController.setValue("This is my title", forKey: "Subject")
Use this line of code to add the subject in the mail, but this will add the subject in default iOS mail, not in the google mail.
let string : String = "Hello this is content to Body of my mail."
let activityViewController = UIActivityViewController(activityItems: [string], applicationActivities: nil)
activityViewController.setValue("Subject Title",forkey "subject")
// This line of code will support alertcontroller as popover for iPAd also.
if let popoverController = activityViewController.popoverPresentationController {
popoverController.sourceView = super.view
}
navigationController?.present(activityViewController, animated: true){
}
Try this:
let obj = UIActivityViewController(activityItems: [Text], applicationActivities: [])
obj.setValue("Your Subject", forKey: "Subject")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With