Reputation:
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 :-(
code:
-(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];
}
Upvotes: 3
Views: 7443
Reputation: 3012
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] addSubview:emailController.view];
on button click:
[[CCDirector sharedDirector] pause]; [[CCDirector sharedDirector] stopAnimation];
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self;
[picker setSubject:@"TEST"]; [picker setMessageBody:@"JAJAJA" isHTML:YES];
[emailController presentModalViewController:picker animated:YES]; [picker release];
delegate method for MFMailComposeViewController
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { [[CCDirector sharedDirector] resume]; [[CCDirector sharedDirector] startAnimation];
[controller dismissModalViewControllerAnimated:NO]; }
Upvotes: 4
Reputation: 2464
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
-(void)emailCallback
{
[[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 :)
Upvotes: 0
Reputation: 8003
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];
}
Upvotes: 0
Reputation: 91
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.
Upvotes: 0