2013-01-05 50 views
0

MFMailComposer中,我附加了MSWord文檔。這些文件附於MFMailComposer。我將這些文件發送到另一個郵件地址。在目標郵件中,這些附件將顯示一個下載選項,而不是一個查看選項。無法在MFMailComposer中附加MSWord文檔

我使用這個代碼

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

您能否分享您用於設置附件的代碼? –

+0

你確定這是正確的MIME類型嗎?網上的參考資料表明應用程序/ msword。 –

+0

在我的應用程序中,我想發送pdf,msword和文本格式的文件 – Goutham

回答

0

你必須設置MSWORD文件的MIME類型..

"application/msword" MIME類型是爲Word 2003名爲 「.doc」 文件類型。正確的MIME類型的Word 2007 「的.docx」 文件是:

application/vnd.openxmlformats-officedocument.wordprocessingml.document 

和更MSWORD MIME類型,使用這些鏈接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"]; 

我認爲這將是對你有所幫助。

+0

我想用pdf,msword和文本格式發送文件 – Goutham

+0

您必須逐個附加數據文件類型wise.I編輯了我的代碼。 –

+0

非常感謝你 – Goutham