0

I´m new on iPhone/iPad development and I am having some problems with a plugin i use for Unity3d.

The plugin popups a MFMailComposeViewController and enables the user to send a email from in-game. When the user is done, the window should disappear and the game continue to run.

This works as intended on the iPad, but not the iPhone.

After the window is removed on the iPhone, the game dont regain control. The graphics is still rendered, but there is no way to tell if the game is still running or if it is just a still image (since it is in a menu with no dynamic graphics)

Here is some code of how this is done:

-(IBAction)launchEmailView:(NSString*)address subject:(NSString*)subject message:(NSString*)message {
    customUIViewController = [[InAppEmailViewController alloc] init];
    [[self getTopApplicationWindow] addSubview:customUIViewController.view];

    MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];

    [controller setSubject:subject];
    [controller setToRecipients:[NSArray arrayWithObject:address]];
    [controller setMessageBody:message isHTML:NO];
    [controller.navigationBar setTintColor:[UIColor redColor]];

    [customUIViewController presentModalViewController:controller animated:YES];
    controller.mailComposeDelegate = self;
    [controller release];
}



-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [customUIViewController dismissModalViewControllerAnimated:YES];
    [customUIViewController.view removeFromSuperview];
    [customUIViewController release];
    controller = nil;
}

Reading the docs i can only assume that is has something to do with this:

presentModalViewController:animated: Presents a modal view managed by the given view controller to the user.

On iPhone and iPod touch devices, the view of modalViewController is always presented full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.

The problem is not with the iPad, so my guess is that i need to handle this differently in fullscreen?

Any help would be greatly appreciated.

Regards, Niklas

[EDIT]

After some commenting back and forth i decided to add the function for finding topWindow

-(UIWindow*)getTopApplicationWindow
{
    UIApplication* clientApp = [UIApplication sharedApplication];
    NSArray* windows = [clientApp windows];
    UIWindow* topWindow = nil;

    if (windows && [windows count] > 0)
            topWindow = [[clientApp windows] objectAtIndex:0];

    return topWindow;
}
Bakery
  • 406
  • 1
  • 5
  • 10
  • The only irregularity I see with adding modalViewControllers I see in your code is the [[self getTopApplicationWindow] addSubview:customUIViewController.view]; Why are you doing that? It is mostlikely causing your problem. – Totumus Maximus Oct 07 '11 at 08:32
  • This is a plugin I am using. I did not build it myself and I am a total beginner on Objective-C, so I dont really know why this is done. I thought this was needed so I have not tried to remove it. I will do that now. – Bakery Oct 07 '11 at 08:36
  • This was actually required for the plugin to work. Since the plugin is called from Unity3d, i quess that i need to find the correct window to attach to. – Bakery Oct 07 '11 at 08:40
  • You will figure it out^^ But if you want to see a working modalViewController prototype check this question (in the first edit). http://stackoverflow.com/questions/7607271/presentmodalviewcontroller-fullscreenmode-issue – Totumus Maximus Oct 07 '11 at 08:43

1 Answers1

0

You should present the mail composer using:

[self presentModalViewController:controller animated:YES];

and in your delegate method you should call:

[self dismissModalViewControllerAnimated:YES];

all assuming that self is a UIViewController

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217