簡體   English   中英

無法在MFMailComposer中附加MSWord文檔

[英]Not Able to Attach MSWord Documents in MFMailComposer

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];

您必須為MSWORD文檔設置mime類型。

"application/msword" MIME類型是單詞2003“ .doc”文件的類型。 單詞2007“ .docx”文件的正確MIME類型是:

application/vnd.openxmlformats-officedocument.wordprocessingml.document

對於更多的msword模仿類型,請使用以下鏈接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"];
    }

編輯:檢查網址包含哪個格式。 我的意思是該網址包含.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"];

我認為這將對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM