注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

IOS & JAVA KEY

(iMilo)

 
 
 

日志

 
 
关于我

All the splendor in the world is not worth a good friend!! Hello my friend!!

网易考拉推荐

iPhone/iPad利用系统MFMailComposeViewController调用系统邮件  

2011-07-04 22:09:16|  分类: IOS |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

 

 

引入:

iPhone/iPad利用系统MFMailComposeViewController调用系统邮件,比如:在程序中点击按钮后,调出发送邮件的界面(MFMailComposeViewController实现).

说明:

MFMailComposeViewController: 类提供了一个标准接口,它管理的编辑和发送电子邮件。您可以使用此视图控制器显示在您的应用程序标准的电子邮件意见,并填充与初始值,如主题,电子邮件收件人,正文和附件,查看字段。用户可以编辑您所指定的初始内容,并选择发送电子邮件或取消操作。

实现:

1、添加类库{Frameworks}MessageUI.framework

2、实现代码:

/*

* @DO 发送邮件

* @param sender

*/

- (void) sendEmail:(id)sender

{

         MFMailComposeViewController *mailCompose = [[MFMailComposeViewController alloc] init];

         if(mailCompose)

         {

              //设置代理

              [mailCompose setMailComposeDelegate:self];

              NSArray *toAddress = [NSArray arrayWithObject:@"****@***.com"];

              NSArray *ccAddress = [NSArray arrayWithObject:@"XXXX@XXX.com"];

              NSString *emailBody = @"<H1>邮件内容!</H1>";

              //设置收件人

              [mailCompose setToRecipients:toAddress];

              //设置抄送人

              [mailCompose setCcRecipients:ccAddress];

              //设置邮件内容           

              [mailCompose setMessageBody:emailBody isHTML:YES];

              //设置邮件主题

              [mailCompose setSubject:@"这里是主题"];

              //设置邮件附件{mimeType:文件格式|fileName:文件名}

              [mailCompose addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"1.png"];

              //设置邮件视图在当前视图上显示方式

              [self presentModalViewController:mailCompose animated:YES];

         }

         [mailCompose release];

}

 

/*

* @DO 代理对邮件发送失败的处理

* @param controller

* @param result

* @param error

*/

-  (void)mailComposeController:(MFMailComposeViewController*)controller

                didFinishWithResult:(MFMailComposeResult)result

                                          error:(NSError*)error

{       

 

         switch (result)

         {

              case MFMailComposeResultCancelled:

              {

                     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send e-mail Cancel"

                                                                                                         message:@""

                                                                                                     delegate:self

                                                                                      cancelButtonTitle:@"OK"

                                                                                      otherButtonTitles:nil];

                     [alert show];

                     [alert release];

              }

                     break;

              case *********:

              {

                     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"E-mail have been saved"

                                                                                                         message:@""

                                                                                                     delegate:self

                                                                                      cancelButtonTitle:@"OK"

                                                                                      otherButtonTitles:nil];

                     [alert show];

                     [alert release];

              }

                     break;

              default:

              {

                     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"E-mail Not Sent"

                                                                                                         message:@""

                                                                                                     delegate:self

                                                                                      cancelButtonTitle:@"OK"

                                                                                      otherButtonTitles:nil];

                     [alert show];

                     [alert release];

              }

                     break;

         }

    //邮件视图消失

         [self dismissModalViewControllerAnimated:YES];

}

说明:*****表示邮件发送失败的错误类型.

-

国际化支持:

方式一、可以在项目的list属性文件中设置Localization native development region的属性值;

方式二、可以在调用MFMailComposeViewControllerxib中设置Localization(方法如下:找到对应xib文件,右击该文件选择Get Infoà [General选项卡下单击{add Localization}])如台湾繁体{zh_TW}

总结:如果是调用MFMailComposeViewController为非xib形式,那就只能用方式一来支持国际化.

其他:

2011-07-04

iMilo

-

 

  评论这张
 
阅读(1094)| 评论(1)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017