iPhone发送的邮件没有附件
我正在尝试使用 MFMailComposeViewController 将录制的声音文件作为附件发送。
声音文件没问题。
选择器显示正确的文件名,将音频文件图标显示为附件,发送邮件,但结果中没有附件。
我在下面附上了发送邮件的来源。有一个“文本/纯文本”内容类型部分,而不是“Content-Disposition:附件;”正如预期的那样。
这是我的代码,用于定义路径并附加音频文件。可能出什么问题了?
#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--
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];
...
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--
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现
[url path]
对于dataWithContentsOfFile
不正确,我使用[[self.recorder url] path]
代替,它工作正常。I found that
[url path]
is not correct fordataWithContentsOfFile
, I used[[self.recorder url] path]
instead and it works fine.