发送电子邮件 - MFMailComposeResult

 dx152 发布于 2023-01-10 11:38

我正在尝试将我的一个应用程序从Obj-C迁移到Swift,我遇到了电子邮件管理方面的问题.
我按小时搜索,但我没有找到如何解决这个问题.
基本上,我正在尝试迁移该func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!)功能.

问题是交换机内没有选项有效.

func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!)
{
    switch result.value
    {
        case CUnsignedInt(MFMailComposeResultCancelled):
            var alert = UIAlertController(
                title: NSLocalizedString("sendingStatus", tableName: "LocalizationFile", comment:"sendingStatus"),
                message: NSLocalizedString("emailCancelledByUser", tableName: "LocalizationFile", comment:"emailCancelledByUser"),
                preferredStyle: UIAlertControllerStyle.Alert)
            self.presentViewController(alert, animated: true, completion: nil)
        case MFMailComposeResult(MFMailComposeResultFailed):
            var alert = UIAlertController(
                title: NSLocalizedString("sendingStatus", tableName: "LocalizationFile", comment:"sendingStatus"),
                message: NSLocalizedString("emailSentFailed", tableName: "LocalizationFile", comment:"emailSentFailed"),
                preferredStyle: UIAlertControllerStyle.Alert)
            self.presentViewController(alert, animated: true, completion: nil)
        case MFMailComposeResultSaved:
            var alert = UIAlertController(
                title: NSLocalizedString("sendingStatus", tableName: "LocalizationFile", comment:"sendingStatus"),
                message: NSLocalizedString("emailSaved", tableName: "LocalizationFile", comment:"emailSaved"),
                preferredStyle: UIAlertControllerStyle.Alert)
            self.presentViewController(alert, animated: true, completion: nil)
        default:
            var alert = UIAlertController(
                title: NSLocalizedString("sendingStatus", tableName: "LocalizationFile", comment:"sendingStatus"),
                message: NSLocalizedString("emailNotSent", tableName: "LocalizationFile", comment:"emailNotSent"),
                preferredStyle: UIAlertControllerStyle.Alert)
            self.presentViewController(alert, animated: true, completion: nil)
    }
}

在此输入图像描述

1 个回答
  • 不要忘记您还可以在特定结果类型上使用.rawValue(.value在较旧版本的Swift中),将变量结果与之比较:

        var result:MFMailComposeResult = MFMailComposeResultCancelled
    
        switch(result.value) { // <-- Here, note .value is being used
            case MFMailComposeResultCancelled.value: // <-- And here as well!
                print("Cancelled")
            default:
                print("Default")
        }
    

    2023-01-10 11:41 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有