0

MFMailComposer我附上 MSWord 文档。这些文件附在MFMailComposer. 我将这些文件发送到另一个邮件地址。在目标邮件中,这些附件显示为带有下载选项而不是查看选项。

我正在使用此代码

NSURL *url = [[NSURL alloc] initWithString:self.fileString];
NSData *attachments = [NSData dataWithContentsOfURL:url];
[mailView addAttachmentData:attachments mimeType:@"application/pdf/text/msword/csv" fileName:self.useridString];
4

1 回答 1

0

您必须为 MSWORD 文档设置 MIME 类型。

"application/msword"MIME 类型是单词 2003 “.doc” 文件的类型。word 2007 ".docx" 文件的正确 MIME 类型是:

application/vnd.openxmlformats-officedocument.wordprocessingml.document

对于更多 msword mimetypes,请使用这些链接link1link2

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"Your Subject"];
    [picker addAttachmentData:yourData mimeType:@"application/csv" fileName:@"fileName"];
    [picker addAttachmentData:yourData mimeType:@"application/vnd.openxmlformats-officedocument.wordprocessingml.document" fileName:@"fileName"];
    }

已编辑: 检查 url 包含哪个格式。我的意思是这个url包含 .pdf 并获取该 pdf。等等...

 NSArray *arrayComp = [self.fileString componentsSeparatedByString:@"/"];
    NSString *fileType = [[[arrayComp lastObject] componentsSeparatedByString:@"."] lastObject];
    NSString *mimeType = [NSString stringWithFormat:@"application/%@",fileType];

    NSURL *url = [[NSURL alloc] initWithString:self.fileString];
    NSData *attachments = [NSData dataWithContentsOfURL:url];
    [picker addAttachmentData:attachments mimeType:mimeType fileName:@"fileName"];

我想这会对你有所帮助。

于 2013-01-05T06:00:11.637 回答