Search code examples
iphoneobjective-ciossmsmessageui

After hitting cancel in a MFMessageComposeViewController nothing happens


After though that after using MFMailComposeViewController the move to MFMessageComposeViewController was straight foward, but there is a catch.

Suppose this code:

MFMessageComposeViewController* mySMS = [[MFMessageComposeViewController alloc] init];
[mySMS setDelegate:self];
[self presentModalViewController:mySMS animated:YES];

It works this way for mails, but in sms you should set different the delegate to an internal structure like this:

[SMS setMessageComposeDelegate:self];

Hope you don not get stuck on this as I did early today.


Solution

  • You need to Implement the delegate method -(void)mailComposeController(MFMailComposeViewController*)controller didFinishWithResult (MFMailComposeResult)result error:(NSError*)error:

    And inside it you should dismiss it yourself:

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