Not receiving attachment sent from iOS app / MFMailComposeViewController

☆樱花仙子☆ 提交于 2019-12-23 03:39:14

问题


I am using MFMailComposeViewController to send attachments (pdfs) from within the app. However I am not receiving the attachments when I test this on a device. Any idea what can be the problem?

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

回答1:


try to understand this code,it helps u.

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

Thanks




回答2:


I was having an issue where mail would be sent sometimes, but not always. It turned out this was actually a problem with my email account in the Mail app on my iPhone. To fix, I did the following:

  1. Delete your mail account from your iPhone.
  2. Re-add the mail account
  3. Reboot your phone - I think this was crucial as it caused some syncing between my mail account and the device.

After those 3 steps, mail magically started sending consistently again from my app.



来源:https://stackoverflow.com/questions/8798710/not-receiving-attachment-sent-from-ios-app-mfmailcomposeviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!