2012-01-27 7 views

答えて

0

メール・作曲・ビュー・コントローラを使用している場合:

[mailComposerViewController addAttachmentData:fileData mimeType:@"text/plain" fileName:@"name_of_text_file"]; 
2

やあこれは私のapp..SOでの作業コードの一種であるこの

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]; 
0

を見てみましょうちょうど従ってください一緒に。 ファイル(テキストファイル)アプリ のマイドキュメントディレクトリにあなたのプロジェクト にMessageUIframeworkを追加したことを確認し、これらの輸入を持っているあなたのインタフェースファイル内

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

@interface Your CLass : UIViewController <MFMessageComposeViewControllerDelegate> 

コード

Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 
    if ([mailClass canSendMail]) 
    { 
     MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
     picker.mailComposeDelegate = self; 

     [picker setSubject:@"Your Subject"];   

     NSFileManager* manager = [[NSFileManager alloc] init]; 
     NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 
     if (![[self NoteFile] isEqualToString:@""]) //check if note is blank 
{ 
      NSString *NoteFilePath = [documentsDirectory 
              stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.txt",[self NoteFileName]]]; 
      NSData *myNoteData = [NSData dataWithContentsOfFile:NoteFilePath]; 
      [picker addAttachmentData:myNoteData mimeType:@"text/plain" fileName:@"Name you want to give your file.txt"]; 
     } 

     [manager release]; 


     // Fill out the email body text 
     NSString *emailBody = @"I am attaching my file!"; 
     [picker setMessageBody:emailBody isHTML:NO]; 

     [self presentModalViewController:picker animated:YES]; 


     [picker release]; 

デリゲートメソッドを使用してさらにメールステータスを確認できます

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
関連する問題