cocos2d MFMailComposeViewController

cocos2d MFMailComposeViewController

Ask Question

10 years, 6 months ago

6 years, 4 months ago

7k times




i tried to insert a mail tool in my app…. my app is based on the cocos2d engine

the Toolbar (at the top ->cancel,send…) is visible but i can’t see the other parts of the mfMailComposerViewController view 🙁


-(void)displayComposerSheet {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@”my message”];

// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@”[email protected]”];
NSArray *ccRecipients = [NSArray arrayWithObjects:@”[email protected]”, @”[email protected]”, nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@”[email protected]”];

[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];

// Attach an image to the email
UIImage *screenshot = [[Director sharedDirector] screenShotUIImage];
NSData *myData = UIImagePNGRepresentation(screenshot);
[picker addAttachmentData:myData mimeType:@”image/png” fileName:@”AdMotiv”];

// Fill out the email body text
NSString *emailBody = @”test”;
[picker setMessageBody:emailBody isHTML:NO];
[[picker view] setFrame:CGRectMake(0.0f,0.0f,320.0f, 480.0f)];

[[picker view] setTransform:CGAffineTransformIdentity];
[[picker view] setBounds:CGRectMake(0.0f,0.0f,320.0f, 480.0f)];
//[[[VariableStore sharedInstance] parentView] setTransform: CGAffineTransformIdentity];
//[[[VariableStore sharedInstance] parentView] setBounds : CGRectMake(0.0f, 0.0f, 480.0f, 320.0f)];

UITextField *textfeld = [[UITextField alloc] initWithFrame:CGRectMake(50.0f, 50.0f, 100.0f, 100.0f)];
[[picker view] addSubview:textfeld];

[[[VariableStore sharedInstance] window]addSubview:picker.view];
[[[VariableStore sharedInstance] window] makeKeyAndVisible];

[picker release];

iphone cocos2d-iphone mfmailcomposeviewcontroller

share|improve this question

edited Nov 17 ’12 at 20:04


9,24444 gold badges4343 silver badges7676 bronze badges

asked Sep 15 ’09 at 14:29


Hi, I too have the same problem. My control is not even entering in to the mail controller. I used a selector in cocos2d to display mail controller. -(void)goToFirstScreen:(id)sender { CCScene *Scene = [CCScene node]; CCLayer *Layer = [mailME node]; [Scene addChild:Layer]; [[CCDirector sharedDirector] setAnimationInterval:1.0/60]; [[CCDirector sharedDirector] pushScene: Scene]; } mailMe is the class name of the mail controller. I think it is wrong to add in this way. How to add it in cocos2d ? Thank You.

– srikanth rongali
May 11 ’10 at 6:56

add a comment

4 Answers





heyyyy finally. i’ve got it working … it seems like the trouble was some animations … … i’ve got it like this now:

on init:

emailController = [[UIViewController
alloc] init]; [[[CCDirector
sharedDirector] openGLView]

on button click:

[[CCDirector sharedDirector] pause];
[[CCDirector sharedDirector]

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

[picker setSubject:@”TEST”]; [picker
setMessageBody:@”JAJAJA” isHTML:YES];

animated:YES]; [picker release];

delegate method for MFMailComposeViewController

error:(NSError*)error { [[CCDirector
sharedDirector] resume]; [[CCDirector
sharedDirector] startAnimation];

share|improve this answer

edited Nov 2 ’13 at 15:43

Krishna Raj Salim

6,65355 gold badges2727 silver badges5858 bronze badges

answered Aug 15 ’10 at 0:43


2,29211 gold badge2121 silver badges2727 bronze badges

add a comment


in the last bit there, change picker to self, and it should work. something to double-check, have you set your class as a delegate? i.e. MFMailComposeViewControllerDelegate in the header? if not, then it won’t be getting the messages.

btw this is in response to the answer you posted, not the initial question.

share|improve this answer

answered Jan 10 ’10 at 0:21


9122 bronze badges

add a comment


Hi I tried with this code and works ( not for the animation, I don’know why, but the picker is removed correctly 🙂

– (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error

//[picker dismissModalViewControllerAnimated:YES];
[picker.view removeFromSuperview];


share|improve this answer

answered May 23 ’10 at 9:23


6,8952020 gold badges6969 silver badges118118 bronze badges

add a comment


Few steps are required to implement inApp email functionality.

Step1: Add the MessageUI frameWork.

Step2: In the .h file,
#import “MessageUI/MessageUI.h”.
Also add delegate MFMailComposeViewControllerDelegate, like and the UIViewController *emailMe;

Step3: In the .m file Add these lines of code in the init function

CCMenuItem *emailItem = [CCMenuItemFont itemFromString: @”Email” target:selfselector:@selector(emailCallback)];
CCMenu *menu = [CCMenu menuWithItems: emailItem, nil];
menu.position = ccp(50,50);
[self addChild:menu];

emailMe = [[UIViewController alloc] init];
[[[CCDirector sharedDirector] openGLView] addSubview:emailController.view];

step 4 : add these methods in .m

[[CCDirector sharedDirector] pause];
[[CCDirector sharedDirector] stopAnimation];

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

[picker setSubject:@”Email test “];
[picker setMessageBody:@”finally its working ” isHTML:YES];

[emailMe presentModalViewController:picker animated:YES];
[picker release];

– (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
[[CCDirector sharedDirector] resume];
[[CCDirector sharedDirector] startAnimation];

[controller dismissModalViewControllerAnimated:NO];

and run the app its done 🙂

share|improve this answer

edited Oct 4 ’11 at 4:17


82088 silver badges1414 bronze badges

answered Jan 13 ’11 at 6:10


2,54911 gold badge2121 silver badges3333 bronze badges

@PriyaKerala: is it not working at all ? elaborate a little bit.

– aToz
Feb 29 ’12 at 5:25

i used this code and then my simulator shows a blank screen nothing related to the mail is getting displayed

– priya
Mar 1 ’12 at 3:40

Its working in iPad, But not in iPhone. <MFMailComposeViewController: 0x152db740> on <UIViewController: 0xc637d60> whose view is not in the window hierarchy!

– Solid Soft
May 5 ’14 at 18:49

add a comment

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password


Post as a guest


Required, but never shown

Post Your Answer


By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

The Overflow Blog

Podcast Episode 220: Fully Remote

Tracking down performance pitfalls in Vue.js

Featured on Meta

Planned maintenance scheduled for Saturday, March 28, 2020 at 13:00 UTC (9AM…

An Update On Creative Commons Licensing

Community and Moderator guidelines for escalating issues via new response…

How does the Triage queue work?

Triage needs to be fixed urgently, and users need to be notified upon…


53How to add a UIImage in MailComposer Sheet of MFMailComposeViewController2MFMailComposeViewController hangs my app0Nothing is editable and no keyboard in MFMailComposeViewController1Mail Composer Problem with app ondevice method1presentModalViewController:picker not working in iPad MFMailComposeViewController5Not able to send email from an app with MFMailComposeViewController31MFMailComposeViewController – iPad0iPhone MFMailComposeViewController

Hot Network Questions

Could Byzantines Bridge a Deep Strait Separating 2 Continents?

Create an ISO of an AWS EC2 Server

circuit analysis transient response in an RC circuit

Safe to mount rear rack for Grail 7.0 al 2020 ( no eyelets )?

Why don’t iron meteorites on Mars rust or oxidize? Why are they shiny?

Could I still play cards from the activated ability of Golos while the Epic effect is active?

Is it true that Netscape Navigator eventually became Mozilla Firefox?

Is travelling with 1 friend permitted in the UK now that the lockdown is enforced?

Is it safe to convert a 256-bit nonce into a 192-bit nonce by SHA-256ing and then truncating it?

Any Implementation in C++

How can an omniscient being have limited awareness?

Does liquid temperature matter when making bread in a bread maker?

Another evidence

Which mobile game featuring a red-roof cartoon house is this?

Why should one pre-heat an oven?

Are force vectors members of a vector space?

How can I get a potential employer to reissue an offer I rejected?

Acquaintance paying friend to do his coding for an ivy league masters. What would you do?

What should I call a “differential” which cubes, rather than squares, to zero?

Is there a Japanese word for “Easter holidays”?

AuraEnabled Method Causes Internal Server Error for non-Admin Profile

How much of the US media referred to the COVID-19 as the “Wuhan Virus” until it received an official designation from the WHO?

Since every human has a different DNA (different combinations of C, G, A, T) what does it mean to have the genome done?

How many cores are used for serial plans in SQL Server?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.


Leave a Reply

Your email address will not be published. Required fields are marked *