I am working on an iPad application that creates a PDF file, which it then sends to the user from the application. I was able to successfully set up email to attach a PDF file, but I cannot remove MFMailComposeViewController. I read several other questions on this subject and tried to imitate what they are doing, but the composer still will not miss. What do I need to change in my code to fire it?
- (IBAction)submitDailyReportButton:(id)sender { MFMailComposeViewController *mail = [[MFMailComposeViewController alloc]init]; [mail setMailComposeDelegate:self]; if ([MFMailComposeViewController canSendMail]) { NSString *email =@ " admin@domain.com "; NSArray *emailArray = [[NSArray alloc]initWithObjects:email,nil]; [mail setToRecipients:emailArray]; [mail setSubject:@"Daily Report"]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *newFilePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"report.pdf"]; NSData *pdfData = [NSData dataWithContentsOfFile:newFilePath]; [mail addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"report.pdf"]; NSString *body = @"Please review the attached daily report"; [mail setMessageBody:body isHTML:NO]; [mail setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; [self presentViewController:mail animated:YES completion:nil]; }else{ NSLog(@"Message cannot be sent"); }
}
source share