目标:实施包含Gmail作为选项的共享表(UIActivityViewController),并设置收件人和主题
问题:设置主题有效,但设置收件人(forKey:"到")会导致程序崩溃。
我希望能够设置共享表电子邮件客户端的发件人和收件人字段,但到目前为止,我一直无法找到任何方法。任何帮助表示赞赏!
相关代码:
let email = ["bob@bobsCompany.com"]
let activityVC = UIActivityViewController(activityItems: [""], applicationActivities: nil)
activityVC.excludedActivityTypes = excludedActivity
activityVC.setValue("Subject Title", forKey: "subject")
activityVC.setValue(email[0], forKey: "to")
activityVC.popoverPresentationController?.sourceView = self.view
self.presentViewController(activityVC, animated: true, completion: nil)
答案 0 :(得分:1)
您只能为UIActivityViewController设置Subject。该程序崩溃,因为没有“到”键。如果要设置收件人和发件人字段,则必须使用MailMFComposeViewController。
if !MFMailComposeViewController.canSendMail()
{
let alertMsg = UIAlertController(title: "Test", message: "Mail services not available.", preferredStyle: UIAlertControllerStyle.Alert)
alertMsg.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alertMsg, animated: true, completion: nil)
}
else
{
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["mail@egmail.com"])
composeVC.setSubject("Subject)
composeVC.setMessageBody("Hi.", isHTML: false)
// Present the view controller modally.
self.presentViewController(composeVC, animated: true, completion: nil)
}