开发者

Disposing MFMailComposeViewController wont bring back my old view on iPhone but works on iPad

开发者 https://www.devze.com 2023-04-11 22:24 出处:网络
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. W

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开发者_如何学Go 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;
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消