我正在尝试将录制的声音文件作为附件发送到MFMailComposeViewController。
声音文件正常。
选择器显示正确的文件名,将音频文件图标显示为附件,发送邮件,但结果中没有附件。
我附在发送邮件的来源之下。有一个“text / plain”内容类型部分而不是“Content-Disposition:attachment;”如预期的那样。
这是我的代码,用于定义路径并附加音频文件。可能有什么不对?
#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--
答案 0 :(得分:0)
我发现[url path]
的{{1}}不正确,我使用了dataWithContentsOfFile
代替它,并且工作正常。