After spending some time looking at similar questions on stack overflow, unfortunately none seemed to resolve my issue.
I'm using a UIActionSheet
, when the user clicks send email on the action sheet, the following code is called:
if ([MFMailComposeViewController canSendMail]){
NSString *emailTitle = @"bla bla bla";
// Email Content
NSString *messageBody = @"bla bla bla";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:@"[email protected]"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
[self.view.window.rootViewController presentViewController:mc animated:YES completion:NULL];
NSLog(@"email view opened");
}
else{
UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No mail account setup on device" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[anAlert addButtonWithTitle:@"Cancel"];
[anAlert show];
}
MFMailComposeViewController
opens on my iPhone in portrait mode, but when opening the app in landscape mode on an iPad, nothing happens. No view pops up, nothing at all.
It shows "email view opened" in the NSLog
but nothing else.
Thoughts?
Edit The app is portrait ONLY on iPhone, and any orientation for iPad
EDIT AGAIN After playing around a bit more, if I assign the code to a button, it works fine, only when selecting email from the action sheet is this problem present
Found the answer, this is it :
dispatch_async(dispatch_get_main_queue(), ^ {
// INSERT EMAIL CODE HERE
});