MFMessageComposeViewController cancel button not working

前端 未结 6 491
慢半拍i
慢半拍i 2021-01-17 10:42

I use this block to send message to the contacts, after sending, the back button is there, but when I touch it nothing happens. Please help me out :)

-(IBAct         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 11:23

    Did you forget to implement mailComposeController:didFinishWithResult: ?...

    - (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
        [controller dismissViewControllerAnimated:YES completion:nil];
    }
    

    From apple documentation:

    // The mail compose view controller delegate method
    - (void)mailComposeController:(MFMailComposeViewController *)controller
                  didFinishWithResult:(MFMailComposeResult)result
                  error:(NSError *)error
    {
        [self dismissModalViewControllerAnimated:YES];
    }
    

    But you can handle all cases depend on your goal ...

提交回复
热议问题