Unable to dismiss MFMailComposeViewController, delegate not called

前端 未结 4 1076
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 12:45

I am calling MFMailComposeViewController from a UITableViewController. Problem is the delegate method is never called when I select Cancel or

4条回答
  •  爱一瞬间的悲伤
    2021-01-30 13:20

    Refer this article for full implementation : http://www.ioscreator.com/tutorials/send-email-from-an-app

    working code after making removing deprecated one :

    #import 
    
    @interface SettingsTableViewController () 
    
    @end
    
    
    @implementation SettingsTableViewController
    // add default methods
    
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSInteger sectionNum = indexPath.section;
        NSInteger rowNum = indexPath.row;
        if (sectionNum == 2 && rowNum == 1) {
            MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
            controller.mailComposeDelegate = self;
            if ([MFMailComposeViewController canSendMail]) {
                [controller setSubject:[NSString stringWithFormat:@"Invitation to Northstar app"]];
                [controller setMessageBody:@" " isHTML:NO];
    //            [controller setToRecipients:[NSArray arrayWithObject:[item objectForKey:@"email"]]];
                //presentViewController:animated:completion:
                [self presentViewController:controller animated:YES completion:NULL];
            }
        }
    }
    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
    {        
        NSLog (@"mail finished");
        [self dismissViewControllerAnimated:YES completion:NULL];
    }
    
    @end
    

提交回复
热议问题