【问题标题】:Setting email sender and recipient from share sheet (ios)从共享表(ios)设置电子邮件发件人和收件人
【发布时间】:2016-08-16 21:38:57
【问题描述】:

目标:实现一个包含 Gmail 作为选项的共享表 (UIActivityViewController),并设置收件人和主题

问题:设置主题有效,但设置收件人(forKey:“to”)使程序崩溃。

我希望能够设置共享表电子邮件客户端的发件人和收件人字段,但到目前为止我还没有找到任何方法来做到这一点。任何帮助表示赞赏!

相关代码:

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)

【问题讨论】:

标签: ios swift


【解决方案1】:

您只能为 UIActivityViewController 设置主题。程序崩溃是因为没有“to”键。如果要设置收件人和发件人字段,则必须使用 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)
    }

【讨论】:

    猜你喜欢
    • 2013-03-30
    • 2013-03-03
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-04
    • 1970-01-01
    相关资源
    最近更新 更多