2013-05-21 45 views
4

我正在創建一個PDF的應用程序,然後用戶從應用程序發送電子郵件的iPad應用程序。我已經能夠成功地設置電子郵件來附加PDF,但我無法讓MFMailComposeViewController解僱。我已經讀過關於這個問題的其他幾個問題,並試圖模仿他們在做什麼,但郵件作曲家仍然不會解僱。我需要在代碼中更改哪些內容才能解僱?爲什麼MFMailComposeViewController在應用內電子郵件過程中不會關閉?

- (IBAction)submitDailyReportButton:(id)sender { 

MFMailComposeViewController *mail = [[MFMailComposeViewController alloc]init]; 
[mail setMailComposeDelegate:self]; 

if ([MFMailComposeViewController canSendMail]) { 

    NSString *email [email protected]"[email protected]"; 
    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"); 

} 

}

回答

13

您必須實現委託方法和罷免的委託方法的視圖控制器。

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

備註 - 如果您無法發送電子郵件,則無需創建郵件編輯器。移動if語句中的分配。

+0

非常感謝!它的工作是正確的。 – user2330744

+0

順便說一句 - 這在'MFMailComposeViewControllerDelegate'參考的描述中有記錄。 – rmaddy

相關問題