从Swift 3发送电子邮件

编程入门 行业动态 更新时间:2024-10-25 11:29:36
本文介绍了从Swift 3发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试设置一个带有发送电子邮件"选项的应用程序.

I am trying to set up an app with send email option.

我有此代码:

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"]) 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中登录了模拟器设备...所以我认为它应该这样做,但事实并非如此.为什么这不起作用?你能告诉我什么地方出了问题,我该如何前进?

So I get this message: "Mail services are not available". Now I've logged in the simulator device in iCloud... So i think it should do it but it's not. Why isn't this working? Can you tell me whats wrong and how can I move forward?

推荐答案

它不适用于模拟器.请在iPhone设备上进行测试.您可以引用 Apple开发人员门户-MFMailComposeViewController

It will not work with simulator. Please test it on iPhone device. You can refer Apple Developer Portal - MFMailComposeViewController

更多推荐

从Swift 3发送电子邮件

本文发布于:2023-10-13 00:22:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486283.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送电子邮件   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!