Question

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.

Was it helpful?

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]; 
}

OTHER TIPS

You can see MFMailComposeResult in Apple documentation

  enum MFMailComposeResult {
    MFMailComposeResultCancelled,
    MFMailComposeResultSaved,
    MFMailComposeResultSent,
    MFMailComposeResultFailed
 };
 typedef enum MFMailComposeResult MFMailComposeResult; 

And you must dismiss controller by yourself in delegate method

 - (void) mailComposeController:(MFMailComposeViewController *)controller          didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
 {
  switch (result){
    case MFMailComposeResultCancelled:
        NSLog(@"Mail cancelled");
        break;
    case MFMailComposeResultSaved:
        NSLog(@"Mail saved");
        break;
    case MFMailComposeResultSent:
        NSLog(@"Mail sent");
        break;
    case MFMailComposeResultFailed:
        NSLog(@"Mail sent failure: %@", [error localizedDescription]);
        break;
    default:
        break;
   }
// Close the Mail Interface
   [self dismissViewControllerAnimated:YES completion:NULL];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top