views:

130

answers:

1

I have a bit of a strange problem. I am trying to send in-app email. I am also using Cocos2d. It works, so far as I get the mail window and I can send mail, but it is extremely slow. It seems to only accept touches every second or so. I checked the cpu usage, and it is quite low. I paused my director, so nothing else should be happening. Any ideas? I am pulling my hair out.

I looked at some examples and did the following:

Made my scene the mail delegate:

@interface MyLayer : CCLayer <MFMailComposeViewControllerDelegate> {
    ...
}

And implemented the following function in the scenes:

-(void) showEmailWindow: (id) sender {
    [[CCDirector sharedDirector] pause];

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

    [picker setSubject: @"My subject here"];

    NSString *emailBody = @"<h1>Here is my email!</h1>";

    [picker setMessageBody:emailBody isHTML:YES];

    [myMail presentModalViewController:picker animated:NO];
    [picker release];

}

I also implemented the mailComposeController, to handle the callback.

A: 

Over at the cocos2d forum (http://www.cocos2d-iphone.org/forum), CJ helped me out.

The important part was that I wasn't calling [dicector stopAnimation], but there were some other good bits, too.

I now do this before I presentModalViewController:

CCDirector *director = [CCDirector sharedDirector];
[director pause];
[director stopAnimation];
[director.openGLView setUserInteractionEnabled:NO];

And then when I get the callback, in mailComposeController, I do this at the end:

CCDirector *director = [CCDirector sharedDirector];
[director.openGLView setUserInteractionEnabled:YES];
[director startAnimation];
[director resume];

[myMail.view.superview removeFromSuperview];

Hope this helps someone else.

Jeff B