2009-11-07 45 views
7

MFMailComposeViewController経由でCSV添付ファイルを送信する際に問題が発生しています。 時にはそれらはうまくいっていますが、他のユーザーのために添付ファイルとして送られるのではなく、電子メールのインラインテキストとして表示されます(< br/>)。誰か私が間違っていることを知っている?ここ は、私のコードの抜粋です:MFMailComposeViewController csv添付ファイルは添付されていませんが、代わりにインラインで表示されます

MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init]; 
mailComposeViewController.mailComposeDelegate = self; 

NSString *csv = @"foo,bar,blah,hello"; 
NSData *csvData = [csv dataUsingEncoding:NSUTF8StringEncoding]; 
[mailComposeViewController addAttachmentData:csvData mimeType:@"text/csv" fileName:@"testing.csv"]; 

[mailComposeViewController setSubject:@"testing sending csv attachment"]; 
[mailComposeViewController setMessageBody:@"csv file should be attached" isHTML:NO]; 
[self presentModalViewController:mailComposeViewController animated:YES]; 

答えて

0

私は、添付ファイルをインライン表示しないようにするためにsetMessageBody:isHTML:に2番目のパラメータがYESでなければならないと考えています。

0

isHTML paramをYESに設定したとしても、メッセージ本文をそのまま表記できる場合は、メッセージ本文をプレーン/テキストとして送信することができます。また、プレーン/テキストメッセージの添付ファイルが一部の電子メールクライアント(Outlook)によって正しく認識されないことがあります。

私の場合、メッセージ本文にリンクを追加すると助けになりました。テキストをHTMLタグで太字に書式設定することも有効です。トリッキー!

iPod 1G 3.1.3でテスト済みです。

10
-(IBAction)btnPressed:(id)sender { 
    NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); 
    NSString *docDir = [arrayPaths objectAtIndex:0]; 
    NSString *Path = [docDir stringByAppendingString:@"/CSVFile.csv"]; 
    NSData *csvData = [NSData dataWithContentsOfFile:Path]; 

    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; 
    controller.mailComposeDelegate = self; 

    [controller setSubject:@"For csv file..."]; 
    [controller setMessageBody:@"...csv file is hear.." isHTML:NO]; 
    [controller addAttachmentData:csvData mimeType:@"text/csv" fileName:@"CSVFile.csv"]; 
    [self presentModalViewController:controller animated:YES]; 
    [controller release]; 
} 
+1

その素晴らしい感謝 – jal

0

これは、ここではケースではないかもしれないが、に注意する一つのことは、ということです:指定されたエンコーディングへの変換が可能でない場合

[NSString dataUsingEncoding:] 

は有効ですが、空のNSDataオブジェクトを返します。

[NSString dataUsingEncoding: s allowLossyConversion: YES] 

また、返されるデータの長さを確認してください。長さがゼロのデータ添付ファイルはメールプロセスのどこかで整えられているようです。

2

こんにちは、私はCSVファイルを作成するためのサンプルコードを入れて、メールでそれを添付しますが、「MessageUI/MessageUI.h」 「MessageUI/MFMailComposeViewController.h」あなたはMessageUI.Frameworkを追加し、それに関連するヘッダをインポートする持っていることを確認してdeligate作ります「MFMailComposeViewControllerDelegateは」...私は他の人

- (void)viewDidLoad { 

arrCsv=[[NSArray alloc]initWithObjects:@"Hello",@"Hi",@"traun",@"fine",nil]; 
NSArray *paths = NSSearchPathForDirectoriesInDomains 

(NSDocumentDirectory, NSUserDomainMask, YES); 

NSString *documentsDirectory = [paths objectAtIndex:0]; 

NSString *fileName = [NSString stringWithFormat:@"%@/try.csv", documentsDirectory]; 

[[arrCsv componentsJoinedByString:@","] writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:NULL]; 

} 



-(ibAction)btnMail { 

NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); 
NSString *docDir = [arrayPaths objectAtIndex:0]; 
NSString *Path = [docDir stringByAppendingString:@"/CSVFile.csv"]; 
NSData *csvData = [NSData dataWithContentsOfFile:Path]; 
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; 
controller.mailComposeDelegate = self; 
[controller setSubject:@"For csv file..."]; 
[controller setMessageBody:@"...csv file is hear.." isHTML:NO]; 
[controller addAttachmentData:csvData mimeType:@"text/csv" fileName:@"CSVFile.csv"]; 
[self presentModalViewController:controller animated:YES]; 
[controller release]; 

} 


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ message.hidden = NO; 
switch (result) 
{ 
    case MFMailComposeResultCancelled: 
     message.text = @"Result: canceled"; 
     break; 
    case MFMailComposeResultSaved: 
     message.text = @"Result: saved"; 
     break; 
    case MFMailComposeResultSent: 
     message.text = @"Result: sent"; 
     break; 
    case MFMailComposeResultFailed: 
     message.text = @"Result: failed"; 
     break; 
    default: 
     message.text = @"Result: not sent"; 
     break; 
} 
[self dismissModalViewControllerAnimated:YES]; 
} 
1

(私はまだ私の延長という名前の「アプリケーション/オクテットストリーム」としてMIMEタイプを設定し、それがインライン添付ファイルを削除するためにトリックを行う必要がありますため、このWLは便利願っていますファイルie pdf)

+0

iOS 8では、これがうまくいきました 私のために。 – lifjoy

+0

iOS 8のjpeg添付ファイルを手伝ってくれませんでしたか? – shelll

関連する問題