views:

247

answers:

1

Hi,
i am using the following code for the mail composer sheet in iPad application. I used the same code for iPhone. It worked.
I am writing the game in iPad using cocos2d. The game is in landScape mode. The control in EmailScene is stopping at [picker presentModalViewController:picker animated:YES]; It is not giving any error. Should I change my code for iPad ?

@interface EmailScene : CCScene <MFMailComposeViewControllerDelegate>
{
    MFMailComposeViewController *picker;
}

-(void)displayComposerSheet;

@end

@implementation EmailScene

- (id) init {
    self = [super init];
   if (self != nil) {
        [self displayComposerSheet];
   }
   return self;
}

// Displays an email composition interface inside the application. Populates all the Mail fields.
-(void)displayComposerSheet
{

    [[CCDirector sharedDirector] pause];

    picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    //Fill in the email as you see fit
    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
    [picker setToRecipients:toRecipients];

    //display the view
    [[[CCDirector sharedDirector] openGLView] addSubview:picker.view];
    [[CCDirector sharedDirector] stopAnimation];  

//When I commented the following two lines the mail page is opening.
    //[picker presentModalViewController:picker animated:YES];

    //[picker release];

}  

But, the problem is my game is in landscape mode and the mail sheet is displayed in portrait mode. Thank you.

A: 

You are using -presentModalViewController:… wrongly. This method should be called on the topmost view controller before the "picker" is presented.

[topmostViewController presentModalViewController:picker animated:YES];

(You shouldn't add picker.view as a subview of the -openGLView either.)

KennyTM
@KennyTM, I had only one view controller and my interface class I added in question. The game is in cocos2d. what will be the topmostViewController in my program ? Thank you.
srikanth rongali
@srikanth: the "topmostViewController" is the view controller that is visible. In your case, it's that "only one view controller".
KennyTM
@KennyTM, In my game only one view controller is there. When we touch a CCLabel in before scene the mail sheet should display. So, I took EmailScene as view controller. Thank you.
srikanth rongali
@Kenny, please check my program once. I have commented two lines. But I have the problem of the mail sheet displaying in portrait mode. How can I convert it in to landscape mode
srikanth rongali
@srik: The mail sheet should take the same orientation as that "only one view controller". If you need landscape mode, that "only one view controller" must also be in landscape mode. Ask a new question for detail.
KennyTM