Search code examples
iphoneiossmsmodalviewcontrollermfmailcomposeviewcontroller

How to run email/sms in landscape iPhone app?


I have an iPhone app, which is running only in landscape mode, but recently I wanted to add mail/sms/facebook features (via UIButton actions). The last one is running smoothly, I launch web browser (itself manages portrait mode), but starting mail or sms composer is driving me mad. I Just want to use this app only in landscape mode, excluding launching mail/sms/fb (browser actually).

I managed to have mail/sms composer in portrait mode when having app screen in landscape, but keyboard appears in landscape too, which is blocking the left/right half of composer - did it with [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

either I'm reading bad stuff on this topic or I'm simply blind ;) - either way any help needed, thanks

EDIT:

I have a root ViewController with overridden:

- (BOOL)shouldAutorotateToInterfaceOrientation

which is returning YES in both landscape modes. This rootVC is firing up ShareVC which has 3 buttons for mail/sms/fb. I wish to acheive something like firing up web browser, which starts in portrait. The same with mail & sms, but using modal view controllers and then returning to ShareVC after sending mail/sms...
I also set orientations in plist to landscape modes. Hope this clarify what I am trying to do :)


Solution

  • Problem fixed :) turned out I was calling present/dismiss modalViewController on a childVC not on rootVC itself, here is code snippet:

    -(IBAction)goMail{
        NSLog(@"gomail...");
        MFMailComposeViewController *picker = [[[MFMailComposeViewController alloc] init] autorelease];
        NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
    
        if ([MFMailComposeViewController canSendMail]) {
            picker.mailComposeDelegate = self;
            [picker setSubject:@"Hello iPhone!"];
    
            // Set up recipients
            NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];
            [picker setToRecipients:toRecipients];
            [picker setMessageBody:@"mail content..." isHTML:NO];
            [self.controller presentModalViewController:picker animated:YES];
            //[picker release];
        }
    }