问题
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:
- Delete your mail account from your iPhone.
- Re-add the mail account
- 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