iPhone发送的邮件没有附件

发布于 2024-08-28 19:37:07 字数 1668 浏览 5 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红颜悴 2024-09-04 19:37:07

我发现 [url path] 对于 dataWithContentsOfFile 不正确,我使用 [[self.recorder url] path] 代替,它工作正常。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文