views:

1507

answers:

5

hi,

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];

}

A: 

I can add the MailComposeViewController to my cocos2d app, I just can't get the compose view to dismiss.

I use this code to add the MailComposeViewController which works fine:

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

// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
[picker setToRecipients:toRecipients];

UIView *theView = [[Director sharedDirector] openGLView];
UIView *pickerView = [[UIView alloc] init];
pickerView = picker.view;
pickerView.tag = 1;
pickerView.frame = theView.frame;
[theView addSubview:pickerView];
[picker presentModalViewController:picker animated:YES];
[picker release];

It sends mail OK but the modal view will not dismiss when you click on either the send button or the cancel button. The MailComposer Delegate method does get called but it does not dismiss the modal view:

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

   [picker dismissModalViewControllerAnimated:YES];

   // This doesn't work either.
   // [controller dismissModalViewControllerAnimated:YES];
}

Does anybody have any ideas?

Smendrick
A: 

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.

bpink
A: 

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];

}

ghiboz
A: 

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]; }
Adka
A: 

i use the MFMailComposeViewController Controller as following :

MFMailComposeViewController *picker1 = [[MFMailComposeViewController alloc] init]; picker1.mailComposeDelegate = self; [picker1 setSubject:@"I have a pencil for you"]; UIImage *roboPic = [UIImage imageNamed:@"RobotWithPencil.jpg"]; NSData *imageData = UIImageJPEGRepresentation(roboPic, 1); [picker addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"RobotWithPencil.jpg"]; NSString *emailBody = @"This is a cool image of a robot I found. Check it out!"; [picker1 setMessageBody:emailBody isHTML:YES]; picker1.navigationBar.barStyle = UIBarStyleBlack; [self presentModalViewController:picker1 animated:YES]; [picker1 release];

when i press button "Cancel" i don't see the panel with "Draft" ,"Save Draft" and "Cancel" buttons , the screen locked/frozen but panel with buttons mention above doesn't appears/not shown .

i will be glade to get any assistance.

Thanks in advance Moshe

Moshe