您的位置:首页 > 移动开发

iOS ---在app里面嵌入发送邮件功能

2013-10-22 18:36 211 查看
1、添加messageUI.FrameWork

2、添加头文件和委托

#import <MessageUI/MessageUI.h>

MFMailComposeViewControllerDelegate
3、MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init]
实例化视图类

mail.mailComposeDelegate = self;
设置委托

[mail setSubject:@"软件分享"];
设置邮件的主题

[mail setMessageBody:@"****用着真不错,赶快下载来试用吧!" isHTML:NO];
设置邮件的内容(两种格式,一种是html,一种是纯文本)

if ([MFMailComposeViewController canSendMail])
{

[self presentModalViewController:mail animated:YES];

[mail release];

}

这时就会出现发送邮件的界面

关于之前设置的委托:

- (void)mailComposeController:(MFMailComposeViewController*)controller

didFinishWithResult:(MFMailComposeResult)result

error:(NSError*)error {

switch (result)

{

case MFMailComposeResultCancelled:

NSLog(@"取消发送mail");

break;

case MFMailComposeResultSaved:

NSLog(@"保存邮件");

break;

case MFMailComposeResultSent:

NSLog(@"发送邮件");

break;

case MFMailComposeResultFailed:

NSLog(@"邮件发送失败: %@...",
[error localizedDescription]);

break;

default:

break;

}

[self dismissModalViewControllerAnimated:YES];

}

原文地址:http://blog.csdn.net/zhibudefeng/article/details/7677421

http://rralun.blog.163.com/blog/static/103904296201262535546154/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐