Ios 从应用程序内发送电子邮件中的图像和文本
如何在我的应用程序中通过电子邮件发送表格数据形式的图像和文本Ios 从应用程序内发送电子邮件中的图像和文本,ios,objective-c,cocoa-touch,ios4,iphone-sdk-3.0,Ios,Objective C,Cocoa Touch,Ios4,Iphone Sdk 3.0,如何在我的应用程序中通过电子邮件发送表格数据形式的图像和文本 请提供帮助和建议。谢谢。您可以使用苹果的MFMailComposeViewController从iOS应用发送邮件。其官方文件是。它的用途 将MessageUI.framework添加到项目中 导入必要的头文件 #import <MessageUI/MessageUI.h> #import <MessageUI/MFMailComposeViewController.h> 如果要附加数据,可以
请提供帮助和建议。谢谢。您可以使用苹果的
MFMailComposeViewController
从iOS应用发送邮件。其官方文件是。它的用途
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
addAttachmentData:
方法
[ctrller addAttachmentData:YOUR_DATA_IN_NSDATA_FORMAT
mimeType:YOUR_MIME_TYPE
fileName:YOUR_ATTACHEMENT_FILENAME];
NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"jpg"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/jpeg" fileName:@"rainy"];
您可以将图像作为附件发送,使用MFMailComposer控制器发送邮件
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Test Subject"];
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@",imageName] ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker setMessageBody:body isHTML:NO];
if (picker != nil) {
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
您可以使用该类来允许用户撰写和发送邮件。您可以使用addAttachmentData:mimeType:fileName:
方法附加图像和其他文件,并使用setMessageBody:isHTML:
方法附加邮件正文(纯文本或HTML)
请注意,目前无法使用多部分/相关
在HTML中包含图像,您必须使用(并非所有客户端都支持)或外部服务器上的图像(出于隐私原因,并非所有客户端都支持)。当然,也可以完全绕过苹果,通过与自己的服务器对话发送邮件
- (void)sendMailWithImage:(UIImage *)image
{
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
if(mailController!=nil) {
mailController.mailComposeDelegate = self;
NSData *imageData = UIImagePNGRepresentation(image);
[mailController addAttachmentData:imageData mimeType:@"image/png" fileName:@"MyImageName"];
[mailController setSubject:yourSubject];
[mailController setMessageBody:yourBody isHTML:NO];
[self presentModalViewController:mailController animated:YES];
[mailController release];
}
else
{
//Do something like show an alert
}
}
希望这有帮助
- (void)sendMailWithImage:(UIImage *)image
{
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
if(mailController!=nil) {
mailController.mailComposeDelegate = self;
NSData *imageData = UIImagePNGRepresentation(image);
[mailController addAttachmentData:imageData mimeType:@"image/png" fileName:@"MyImageName"];
[mailController setSubject:yourSubject];
[mailController setMessageBody:yourBody isHTML:NO];
[self presentModalViewController:mailController animated:YES];
[mailController release];
}
else
{
//Do something like show an alert
}
}