您必须为 MSWORD 文档设置 MIME 类型。
"application/msword"
MIME 类型是单词 2003 “.doc” 文件的类型。word 2007 ".docx" 文件的正确 MIME 类型是:
application/vnd.openxmlformats-officedocument.wordprocessingml.document
对于更多 msword mimetypes,请使用这些链接link1和link2
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"];
我想这会对你有所帮助。