【问题标题】:There is no attachment in the sent mail by iPhoneiPhone发送的邮件中没有附件
【发布时间】:2010-04-11 14:56:10
【问题描述】:

我正在尝试使用 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--

【问题讨论】:

    标签: iphone email attachment mfmailcomposeviewcontroller


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2014-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-23
      • 2017-09-13
      • 1970-01-01
      • 2017-07-31
      相关资源
      最近更新 更多