zoukankan      html  css  js  c++  java
  • iOS开发之---发送邮件

    通过邮件视图控制器封装了邮件发送功能,开发者不需要知道不同的邮件协议或者如何与邮件服务器连接建立等。在iOS中,这些功能都被打包好,通过

    MFMailComposeViewController提供给我们。

    引入MessageUI库。

    搭建UI界面,添加按钮的事件响应方法:

    - (IBAction)demoAction:(id)sender {
        UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"请选择任务" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"打开邮件" otherButtonTitles:@"打开微博",@"打开微信", nil];
        [action showInView:self.view];
    }

    效果:

    动作表单代理方法:

    #pragma mark - UIActionSheet代理方法
    // 处理动作表单点击事件
    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex == 0) {
            MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
            mailVC.mailComposeDelegate = self;
            [mailVC setSubject:@"发送测试邮件"];
            [mailVC setMessageBody:@"测试内容" isHTML:NO];
            [self presentViewController:mailVC animated:YES completion:nil];
        }
    }

    效果:

    处理邮件发送的代理方法:

    #pragma mark - MFMailComposeViewControllerDelegate方法
    - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
    {
        switch (result) {
            case MFMailComposeResultCancelled:
                NSLog(@"取消发送邮件");
                [controller dismissViewControllerAnimated:YES completion:nil];
                break;
                
            case MFMailComposeResultSent:
                NSLog(@"邮件发送成功");
                [controller dismissViewControllerAnimated:YES completion:nil];
                break;
            case MFMailComposeResultFailed:
                NSLog(@"邮件发送失败");
                break;
            case MFMailComposeResultSaved:
                NSLog(@"邮件成功保存");
                [controller dismissViewControllerAnimated:YES completion:nil];
            default:
                break;
        }
    }

    点击发送按钮:

    附注:

    modal展示:presentViewController: animated: completion: 对应dismissViewControllerAnimated: completion:

    push展示:push....对pop.....

  • 相关阅读:
    Kubernetes 弹性伸缩全场景解析 (四)- 让核心组件充满弹性
    15分钟在笔记本上搭建 Kubernetes + Istio开发环境
    idea 插件的使用
    jQuery获取select元素选择器练习
    【Maven】添加ueditor到maven本地仓库
    jQuery序列化乱码解决
    Linux安装RedHat
    MyBatis SQL xml处理小于号与大于号
    js判断数据类型
    基于SSM框架的通用权限框架设计
  • 原文地址:https://www.cnblogs.com/yaoxc/p/3728539.html
Copyright © 2011-2022 走看看