开发者

There is no attachment in the sent mail by iPhone

I'm trying to send a recorded sound file as attachment with MFMailComposeViewController.

The sound file is OK.

The picker shows the correct file name, shows the audio file icon as attachment, sends the mail, but there is no attachment in the result.

I attached below the source of the sent mail. There is a "text/plain" content type part instead of "Content-Disposition: attachment;" as expected.

This is my code code to define the path and attach the audio file. What could be wrong?

#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
#define FILEPATH [DOCUMENTS_FOLDER stringByAppendingPathComponent:[self dateString]]

...

NSURL *url = [NSURL fileURLWithPath:FILEPATH];
self.recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
开发者_JAVA百科

...

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSURL *url = [NSURL fileURLWithPath: [NSString stringWithFormat:@"%@", [self.recorder url]]];
NSData *audioData = [NSData dataWithContentsOfFile:[url path]];
[picker addAttachmentData:audioData mimeType:@"audio/wav" fileName:[[url path] lastPathComponent]];

and the source of the sent mail:

Content-type: multipart/mixed; boundary=Apple-Mail-1-614960740
Content-transfer-encoding: 7bit
MIME-version: 1.0 (iPod Mail 7E18)
Subject: Sound message:
Date: Sun, 11 Apr 2010 11:58:56 +0200

X-Mailer: iPod Mail (7E18)

--Apple-Mail-1-614960740

Content-Type: text/plain;
    charset=us-ascii;
    format=flowed
Content-Transfer-Encoding: 7bit

It is a text here

--Apple-Mail-1-614960740
Content-Type: text/plain;
    charset=us-ascii;
    format=flowed
Content-Transfer-Encoding: 7bit

Sent from my iPod
--Apple-Mail-1-614960740--


I found that [url path] is not correct for dataWithContentsOfFile, I used [[self.recorder url] path] instead and it works fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜