【发布时间】:2016-11-30 11:54:40
【问题描述】:
我正在尝试设置一个带有发送电子邮件选项的应用程序。
我有这个代码:
import Foundation
import MessageUI
import UIKit
class emailClass: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
return
}
sendEmail()
}
func sendEmail() {
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["address@example.com"])
composeVC.setSubject("Hello!")
composeVC.setMessageBody("Hello this is my message body!", isHTML: false)
// Present the view controller modally.
self.present(composeVC, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Check the result or perform other tasks.
// Dismiss the mail compose view controller.
controller.dismiss(animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
所以我收到这条消息:“邮件服务不可用”。 现在我已经在 iCloud 中登录了模拟器设备......所以我认为它应该这样做,但事实并非如此。为什么这不起作用?你能告诉我哪里出了问题,我该如何继续前进?
【问题讨论】:
-
您是否为您的设备配置了电子邮件地址?如果没有,那就去做吧……它可能会解决你的问题。
-
我正在使用模拟器。如何使用电子邮件地址配置设备?当我进入设置时,我看不到“电子邮件”选项......
-
我的东西,你已经解决了这个问题.. 同时这里是为 iOS 设备配置电子邮件的链接...... support.apple.com/en-in/HT201320
-
100% 工作和测试在这里,stackoverflow.com/questions/36838166/…
标签: ios swift iphone swift3 messageui