如何在iphone应用程序中随邮件附加文本文件?

如何在iphone应用程序中随邮件附加文本文件?,iphone,ios4,Iphone,Ios4,我正在使用Objective-C开发一个iPhone应用程序,在这个应用程序中,我必须附加一个文本文件来发送电子邮件。有人能帮我吗?如果您使用的是mail composer视图控制器: [mailComposerViewController addAttachmentData:fileData mimeType:@"text/plain" fileName:@"name_of_text_file"]; 嗨,看看这个 MFMailComposeViewController *composer =

我正在使用Objective-C开发一个iPhone应用程序,在这个应用程序中,我必须附加一个文本文件来发送电子邮件。有人能帮我吗?

如果您使用的是mail composer视图控制器:

[mailComposerViewController addAttachmentData:fileData mimeType:@"text/plain" fileName:@"name_of_text_file"];
嗨,看看这个

MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
[composer setSubject:@"Subject"];
NSString *fullPath =//get path of the file
NSData *fileData = [NSData dataWithContentsOfFile:fullPath];
[composer addAttachmentData:fileData 
                 mimeType:@"text/plain" 
                 fileName:@"File_Name"];        
NSString *emailBody = [NSString stringWithString:@"Body"];
[composer setMessageBody:emailBody isHTML:YES];

[self presentModalViewController:composer animated:YES];
[composer release];

这是我的应用程序中的一种工作代码。所以请继续。 该文件(文本文件)位于应用程序的“我的文档”目录中 确保已将MessageUIframework添加到项目中 并将这些导入到您的接口文件中

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

@interface Your CLass : UIViewController <MFMessageComposeViewControllerDelegate>
您可以使用其委托方法进一步检查邮件状态

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error