iPhone/iPad利用系统MFMailComposeViewController调用系统
来源:互联网 发布:笔记本电脑评测软件 编辑:程序博客网 时间:2024/05/16 07:11
引入:
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的属性值;
方式二、可以在调用MFMailComposeViewController的xib中设置Localization(方法如下:找到对应xib文件,右击该文件选择Get Info [General选项卡下单击{add Localization}])如台湾繁体{zh_TW}
总结:如果是调用MFMailComposeViewController为非xib形式,那就只能用方式一来支持国际化.
其他:
2011-07-04
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的属性值;
方式二、可以在调用MFMailComposeViewController的xib中设置Localization(方法如下:找到对应xib文件,右击该文件选择Get Info [General选项卡下单击{add Localization}])如台湾繁体{zh_TW}
总结:如果是调用MFMailComposeViewController为非xib形式,那就只能用方式一来支持国际化.
其他:
2011-07-04
iMilo
原著地址:http://www.7xz.com/topic?tid=3039
- iPhone/iPad利用系统MFMailComposeViewController调用系统
- iPhone/iPad利用系统MFMailComposeViewController调用系统邮件
- Iphone利用UIImagePickerController调用系统照相机
- Iphone利用UIImagePickerController调用系统照相机
- Iphone利用UIImagePickerController调用系统照相机
- Iphone利用UIImagePickerController调用系统照相机
- iOS 判断iphone ipad 系统版本
- iOS 判断iphone ipad 系统版本
- iOS 判断iphone ipad 系统版本
- (iPhone/iPad)代码调用“设置”中的定位服务And系统其他相关功能设置
- (iPhone/iPad)代码调用“设置”中的定位服务And系统其他相关功能设置
- (iPhone/iPad)代码调用“设置”中的定位服务And系统其他相关功能设置
- iphone 程序 调用系统程序
- iPhone如何调用系统声音?
- iPhone、iPad等iOS系统界面设计字体规范
- JS判断 iPad|iPod|iPhone|Android 系统访问
- IOS(iPad、iPhone)删除已下载系统更新
- IOS 系统,iphone ,ipad 等导入音视频铃声
- String,StringBuffer,StringBulider的区别
- 1.Oracle Database Vault - Realm
- 机遇lan的数据备份
- Android TextView 使用HTML格式串
- 解决L2TP_VPN_768#连接错误的方法
- iPhone/iPad利用系统MFMailComposeViewController调用系统
- C#中Show()和ShowDialog()的区别
- 线程的一些基本概念
- PHP中的魔术方法,转自:http://4nail.iteye.com/blog/604913
- 总结:Android JNI开发疑点
- C#异步调用四大方法详解
- 网贴:打造最专业的VB6服务器应用开发-VB6真正的多线程
- android中自定义service的详解(例子)
- hibernate错误:Could not determine type for: java.util.Set