【问题标题】:sending doc file as an attachment on iPad在 iPad 上将 doc 文件作为附件发送
【发布时间】:2011-04-01 05:47:38
【问题描述】:

我想以编程方式从我的应用程序中将 .doc 文件作为电子邮件附件发送。

【问题讨论】:

  • 这是一个预先存在的 .doc 文件,还是动态生成的?
  • 我正在通过我的应用程序动态创建它

标签: objective-c ipad mfmailcomposeviewcontroller


【解决方案1】:

使用 -[MFMailComposeViewController addAttachmentData:] 的 mimeType 为“application/msword”。例如:

- (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:@"first@example.com"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

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

【讨论】:

  • 我只使用此代码。唯一的区别是我在文档目录中有 .doc 文件。此邮件附件在 mac 上打开,但在 ipad 上不打开
  • 打开是指以 doc 文件的形式打开并以可读的方式打开,还是以检测到的方式打开并可以保存到应用沙箱中?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-03
  • 1970-01-01
  • 1970-01-01
  • 2021-01-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多