0

我正在尝试使用 MFMailComposeViewController 将录制的声音文件作为附件发送。

声音文件没问题。

选择器显示正确的文件名,将音频文件图标显示为附件,发送邮件,但结果中没有附件。

我附在已发送邮件的来源下方。有一个“文本/纯”内容类型部分,而不是“内容处置:附件;” 正如预期的那样。

这是我定义路径并附加音频文件的代码。有什么问题?

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

...

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

以及发送邮件的来源:

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--
4

1 回答 1

0

我发现这[url path]不正确dataWithContentsOfFile,我[[self.recorder url] path]改用它,它工作正常。

于 2010-04-12T14:54:09.467 回答