2011-04-01 54 views
1

我想以編程方式從我的應用發送.doc文件作爲電子郵件附件。在iPad上發送doc文件作爲附件

+0

這是一個預先存在的.doc文件,還是一個動態生成的文件? – 2011-04-01 05:52:28

+0

我通過我的應用程序動態創建它 – Swastik 2011-04-01 06:41:18

回答

6

使用mimeType爲「application/msword」的[MFMailComposeViewController addAttachmentData:]。例如:

- (void)displayComposerSheet { 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    [picker setSubject:@"I'm attaching a word document!"]; 

    // Set up recipients 
    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

    [picker setToRecipients:toRecipients]; 
    [picker setCcRecipients:ccRecipients]; 
    [picker setBccRecipients:bccRecipients]; 

    // Attach a doc to the email 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"MyDocument" ofType:@"doc"]; 
    NSData *myData = [NSData dataWithContentsOfFile:path]; 
    [picker addAttachmentData:myData mimeType:@"application/msword" fileName:@"MyDocument"]; 

    // Fill out the email body text 
    NSString *emailBody = @"Please see the attached document."; 
    [picker setMessageBody:emailBody isHTML:NO]; 

    [self presentModalViewController:picker animated:YES]; 
    [picker release]; 
} 
+0

我只使用此代碼。唯一不同的是,我在文檔目錄中有.doc文件。此郵件附件在Mac上打開但不在ipad上 – Swastik 2011-04-01 06:45:06

+0

通過打開,您的意思是打開並且可以作爲doc文件讀取,或者在檢測到時打開並保存到應用程序沙箱中? – 2011-04-01 21:50:39

相關問題