未收到iOS app / MFMailComposeViewController发送的附件

时间:2012-01-10 04:51:51

标签: objective-c ios mfmailcomposeviewcontroller

我正在使用MFMailComposeViewController从应用内发送附件(pdf)。但是,当我在设备上测试时,我没有收到附件。知道可能是什么问题吗?

- (void) emailDocument 
{
    MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];

    NSData *data = [[NSData alloc] initWithContentsOfURL:pdfURL];


    mailController.mailComposeDelegate = self;

    [mailController setSubject:[self title]];
    [mailController setMessageBody:@"Please find the attached documents." isHTML:YES];
    [mailController addAttachmentData:data mimeType:@"application/pdf" fileName:@"document"];
    [self presentModalViewController:mailController animated:YES];
}

2 个答案:

答案 0 :(得分:1)

尝试理解这段代码,它有助于你。

- (void)viewDidLoad 
{
if ([MFMailComposeViewController canSendMail])

    myButton.enabled = YES;
}


- (IBAction)buttonPressed 
{
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];

    mailController.mailComposeDelegate = self;

    [mailController setSubject:@"Hello iPhone"];

    [mailController setMessageBody:@"This is the MailSend Application...." isHTML:NO];

    [self presentModalViewController:mailController animated:YES];

    [mailController release];
}  

- (void)mailComposeController:(MFMailComposeViewController*)mailController didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{
[self becomeFirstResponder];

    [self dismissModalViewControllerAnimated:YES];
}

由于

答案 1 :(得分:0)

我遇到了有时会发送邮件的问题,但并非总是如此。事实证明这实际上是我的iPhone上的邮件应用程序中的电子邮件帐户的问题。为了解决这个问题,我做了以下几点:

  1. 从iPhone删除您的邮件帐户。
  2. 重新添加邮件帐户
  3. 重新启动手机 - 我认为这很重要,因为它会导致我的邮件帐户和设备之间发生一些同步。
  4. 在这3个步骤之后,邮件神奇地开始从我的应用程序再次发送。