使 MFMailComposeViewController 在发送时消失

making MFMailComposeViewController disappear upon sending

所以我知道我必须使用 MFMailComposeResultSent。 (至少我认为那是我应该使用的)这是我拥有的代码,它发送电子邮件和一切正常,但邮件编辑器保持运行。

编辑:这是我的代码

    if ([condition  isEqual: @"Excellent"] && [MFMailComposeViewController canSendMail]) {
    NSString *emailBody = [NSString stringWithFormat:@"Product:%@    Make:%@   Year Manufactured:%@  Description:%@  Condition:Excellent Email:%@",inputProduct,inputMake,inputYear,inputDescript, inputEmail];
    NSArray *recipient = [NSArray arrayWithObject:@"LoveShackElectronics@gmail.com"];
    MFMailComposeViewController *SuperLovedEmail = [[MFMailComposeViewController alloc]init];
    [SuperLovedEmail setTitle:emailTitle];
    [SuperLovedEmail setToRecipients:recipient];
    [SuperLovedEmail setMessageBody:emailBody isHTML:NO];
    [SuperLovedEmail setUserActivity:false];
    [self presentViewController:SuperLovedEmail animated:YES completion:nil];

}
else {
    UIAlertController *emailAlert = [UIAlertController alertControllerWithTitle:@"Oh No!" message:@"Your Phone is not able to send an email currently or you have not chosen a condition. Please make sure you have chosen a condition and that you are signed in through Mail" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *emailAlertAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * emailAlertAction) {}];
    [emailAlert addAction:emailAlertAction];
    [self presentViewController:emailAlert animated:YES completion:nil];
}

您需要将 SuperLovedEmail 对象的 mailComposeDelegate 属性 设置为 self,然后处理 didFinishWithResult 消息,如下所示:

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

您可能会发现评估 MFMailComposeResult 以查看发送是否真的发生了。