Bill Norman Bill Norman - 27 days ago 8
iOS Question

iOS 11 beta: Mail View Controller called from app will not send mail

I'm having to update an enterprise app for use on 64-bit iOS devices running iOS 11 beta 3. The app composes an email which contains specific data, and the user sends the email to the server, where it is processed to extract the data. (I would prefer to send it to the server via TCP, but that was not my decision.)

The app is fully functional in that it will compose the email body with the specific data, address it to the server email box, and present the view with the "Send" button at the top. But tapping the "Send" button does nothing. For that matter, tapping the "Cancel" button only brings up that alert asking to make sure you want to cancel, and with either response, the email view is not dismissed.

Here's the Mail Compose code:

NSString *strEmailAddress = [[NSUserDefaults standardUserDefaults] objectForKey:kEmailAddress];
NSArray *listOfRecipients = [[NSArray alloc] initWithObjects:strEmailAddress, nil];

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@"Equipment Inventory"];
[mailViewController setMessageBody:totalArray isHTML:NO];
[mailViewController setToRecipients:listOfRecipients];
[self presentViewController:mailViewController animated:YES completion:nil];


This is what I used in the previous 32-bit version of the app, and it has worked fine for over five years.

Because I'm dealing with betas for both iOS and Xcode, how can I figure out if this is a bug in the OS or in the code? No errors are shown either in Xcode or on the phone.

Thanks for any help.

Answer Source

You need to implement the delegate method and dismiss the controller.

the method will provide an error if accord.

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(nullable NSError *)error {

   [controller dismissViewControllerAnimated:true completion:nil];
}