iOS_开发_Send_Mail
来源:互联网 发布:js去重最优算法 编辑:程序博客网 时间:2024/05/16 18:24
- MFMailComposeViewControl
ler
MFMailComposeViewControl
- 1.项目中引入MessageUI.framework;
- 2.在使用的文件中导入MFMailComposeViewControl
ler.h头文件; - 3.实现MFMailComposeViewControl
lerDelegate,处理邮件发送事件; - 4.调出邮件发送窗口前先使用MFMailComposeViewControl
ler里的“+ (BOOL)canSendMail”方法检查用户是否设置了邮件账户; - 5.初始化MFMailComposeViewControl
ler,构造邮件体
- #import
- #import
- @interface
ViewController : UIViewController - @end
- #pragma
mark - 在应用内发送邮件 - //激活邮件功能
- -
( void)sendMailInApp - {
-
Class mailClass = (NSClassFromString(@ ler" )); -
(!mailClass) { -
[self alertWithMessage:@ -
-
} -
(![mailClass canSendMail]) { -
[self alertWithMessage:@ -
-
} -
[self displayMailPicker]; - }
-
- //调出邮件发送窗口
- -
( void)displayMailPicker - {
-
MFMailComposeViewControl ler *mailPicker = [[MFMailComposeViewControl ler alloc] init]; -
mailPicker.mailComposeDelegate = self; -
-
[mailPicker setSubject: @ -
-
NSArray *toRecipients = [NSArray arrayWithObject: @ -
[mailPicker setToRecipients: toRecipients]; -
-
NSArray *ccRecipients = [NSArray arrayWithObjects:@ @ "third@example.com",nil]; -
[mailPicker setCcRecipients:ccRecipients]; -
-
NSArray *bccRecipients = [NSArray arrayWithObjects:@ nil]; -
[mailPicker setBccRecipients:bccRecipients]; -
-
添加一张图片 -
UIImage *addPic = [UIImage imageNamed: @ -
NSData *imageData = UIImagePNGRepresentation (addPic); png -
-
[mailPicker addAttachmentData: imageData mimeType: @ fileName: "Icon.png"];@ -
-
-
NSString *file = [self fullBundlePathFromRelati vePath:@ -
NSData *pdf = [NSData dataWithContentsOfFile:file]; -
[mailPicker addAttachmentData: pdf mimeType: @ fileName: "高质量C++编程指南.pdf"];@ -
//添加一个视频 -
NSData *video = [NSData dataWithContentsOfFile:path]; [mailPicker -
NSString *emailBody = @ 正文"; -
[mailPicker setMessageBody:emailBody isHTML:YES]; -
[self presentModalViewControll er: mailPicker animated:YES]; -
[mailPicker release]; - }
- #pragma
mark - 实现 MFMailComposeViewControl lerDelegate - -
( void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error - {
//关闭邮件发送窗口 -
[self dismissModalViewControll erAnimated:YES]; -
NSString *msg; -
(result) { -
MFMailComposeResultCance lled: -
msg = @ -
-
MFMailComposeResultSaved : -
msg = @ -
-
MFMailComposeResultSent: -
msg = @ -
-
MFMailComposeResultFaile d: -
msg = @ -
-
-
msg = @ -
-
} -
[self alertWithMessage:msg]; - }
0 0
- iOS_开发_Send_Mail
- iOS_高效开发之道
- iOS_高效开发之道
- iOS_高效开发之道
- iOS_高效开发之道
- 尝鲜delphi开发android/ios_环境搭建
- 尝鲜delphi开发android/ios_试试示例
- iOS_基于百度地图的开发
- iOS_开发_工具_Terminal命令
- iOS_开发中常用宏定义
- iOS_开发经验总结:键盘遮挡输入框时的解决方法
- iOS_开发中遇到的那些问题_1
- iOS_开发_工具_mac下的brew安装方法
- iOS_开发_工具_mac下加密文件
- iOS_开发中遇到的那些问题_6
- iOS_开发中遇到的那些问题_3
- iOS_开发中遇到的那些问题_2
- iOS_开发中遇到的那些问题_4
- java虚拟机参数备份
- 黑马程序员_集合的概述
- Oslo.Messaging 中的 Message 处理
- 论文阅读笔记:图像分割方法deeplab以及Hole算法解析
- Unity制作Loading详解
- iOS_开发_Send_Mail
- oslo.messaging组件的学习之call方法
- 微软2015年从沉睡巨人到技术领先者
- Unity3D研究院之异步加载游戏场景与异步加载游戏资源进度条(三十一)
- Java程序性能相关
- iOS_UITableView_不显示无内容部分的分割线
- Dinner(南阳oj218)(水题,主要是测试数据太弱了)
- Android studio安装过程
- 思维 Codeforces491B New York Hotel