我正在制作一个iPad应用程序,用于创建PDF,然后用户通过该应用程序发送电子邮件。我已经能够成功设置电子邮件以附加PDF,但我无法让MFMailComposeViewController解散。我已经阅读了关于这个问题的其他几个问题,并试图模仿他们正在做什么,但邮件编写者仍然不会解雇。我需要在代码中进行哪些更改才能将其解雇?
- (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");
}
}
答案 0 :(得分:13)
您必须实现委托方法并在委托方法中关闭视图控制器。
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissViewControllerAnimated:YES completion:nil];
}
旁注 - 如果您无法发送电子邮件,则无需创建邮件编辑器。在if
语句中移动分配。