My MFMailComposeViewController in iOS6 no longer works

It is noted that my MFMailComposeViewController, which I use to create an email dialog for sending email, no longer works in iOS6. It still displays a dialog, but I cannot set the body text or enter anything into the view. All I can do is click Cancel.

The class implements the MFMailComposeViewControllerDelegate interface, and here is some code:

//h file @interface ASEmailSender : NSObject //m file @implementation MyEmailSender () <MFMailComposeViewControllerDelegate> @end @implementation MyEmailSender ... - (void)emailFile:(ASFile *)file inController:(UIViewController *)viewController { MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; if ([MFMailComposeViewController canSendMail]) { mailController.mailComposeDelegate = self; [mailController setSubject:@"my subject"]; [mailController setMessageBody:@"msg body here" isHTML:NO]; [viewController showIsLoading:YES]; self.viewController = viewController [viewController presentModalViewController:mailController animated:YES]; } } - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { [self.viewController dismissModalViewControllerAnimated:YES]; } 

It works great in iOS5.

+4
source share
2 answers

I fixed this by changing MyEmailSender as a UIViewController, not NSObject. For some reason, this fixes an issue when working in iOS6. The new code looks like this:

 //h file @interface ASEmailSender : UIViewController <MFMailComposeViewControllerDelegate> //m file @implementation MyEmailSender ... (same functions as before) 

Now it works in both iOS5 and iOS6.

+1
source

I fixed the same problem (in iOS6: only the Cancel button works on the composer's blank screen, whereas in iOS5 the same code works fine.)

I imported:

 #import <MessageUI/MFMailComposeViewController.h> 

But I forgot about it:

 #import <MessageUI/MessageUI.h> 

After adding the import, MessageUI.h has more problems in iOS 6.

0
source

Source: https://habr.com/ru/post/1441668/


All Articles