I have an app that I set to Landscape Left, Landscape Right and Portrait in my Info-plist. However, I am generally operating in a Landscape mode for all of my view controllers and I have set
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;}
Except for the view controller where I have a button that I want to allow the user to send emails.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{return YES;}
When I try to send an email my app crashes. It works just fine on my iPad. Here is my code for sending the email.
- (IBAction)sendEmail:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:@"HI!"];
UIImage *myImage = [UIImage imageNamed:@"myPicture.png"];
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailComposer addAttachmentData:imageData mimeType:@"image/png" fileName:@"FullTitle.png"];
NSString *emailBody = @"Hi there!!";
[mailComposer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device does not support email function"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved: you saved the email message in the drafts folder.");
break;
case MFMailComposeResultSent:
NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
break;
default:
NSLog(@"Mail not sent.");
break;
}
[self dismissModalViewControllerAnimated:YES];
}
I'm not sure, but I may have somehow locked myself in Landscape mode and so when I want to send an email, the iPhone wants to rotate to Portrait, but seems is not allowed to. I am not seeing any error messages in my console. Thanks in advance for your help.