John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 988 forks source link

MFMailComposeViewController's mailComposeDelegate doesn't fire #144

Closed sldennis closed 10 years ago

sldennis commented 10 years ago

After presenting a MFMailComposeViewController from the rearViewController, and setting the mailComposeDelegate to the rearViewController, the mailComposeDelegate just will not fire off after user click either the Send or Cancel button. Thus I could not dismiss the MFMailComposeViewController.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

SWRevealViewController *revealController = self.revealViewController;
UINavigationController *frontNavigationController = (id)revealController.frontViewController;

[revealController setFrontViewPosition:FrontViewPositionRightMost animated:YES];

        if ([MFMailComposeViewController canSendMail]) {

            MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
            [mailViewController setSubject:NSLocalizedString(@"Feedback", nil)];
            [mailViewController setToRecipients:[NSArray arrayWithObject:@"feedback@myemail.com"]];
            [mailViewController setMailComposeDelegate:self];

            [self presentViewController:mailViewController animated:YES completion:^(void){}];

        }else{
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Feedback", nil) message:NSLocalizedString(@"DeviceCannotSendEmail", nil) delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alertView show];
        }
}

-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{

    [self dismissViewControllerAnimated:YES completion:NULL];

    if (result == MessageComposeResultSent) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Feedback", nil) message:NSLocalizedString(@"FeedbackSent", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", nil) otherButtonTitles:nil, nil];
        [alertView show];
    }else if (result == MessageComposeResultCancelled){
        //do nothing if user cancelled
    }else if (result == MessageComposeResultFailed){
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Feedback", nil) message:NSLocalizedString(@"MessageNotSent", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", nil) otherButtonTitles:nil, nil];
        [alertView show];
    }

    [self.revealViewController setFrontViewPosition:FrontViewPositionRight animated:YES];

}

sldennis commented 10 years ago

Hi sorry, realised my mistake in the delegate function name. Realised i wrongly used the messageComposeViewController instead of the mailComposeViewController, eye blur @_@, my bad!