Cocos2d MFMailComposeViewController

I tried to insert a mail tool into my application .... my application is based on the cocos2d engine

The toolbar (at the top → cancel, send ...) is visible, but I do not see 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:@"first@example.com"]; 
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

[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];
}
+3
source share
4 answers

gayyyy finally. it works for me ... it seems that the problem was in some animations ...... I now have this:

in init:

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

when a button is pressed:

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

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

[ Subject: @ "TEST" ]; [ setMessageBody: @ "JAJAJA" isHTML: YES];

[emailController presentModalViewController: : ]; [];

MFMailComposeViewController

- () mailComposeController: (MFMailComposeViewController *) didFinishWithResult: (MFMailComposeResult) error: ( NSError *) {[[CCDirector sharedDirector] resume]; [[CCDirector sharedDirector] startAnimation];
  [ dismissModalViewControllerAnimated: NO]; }

+4

, picker self, . -, , ? .. MFMailComposeViewControllerDelegate ? , .

btw , , .

0

, ( , , :)

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

{
  // [picker ModalViewControllerAnimated: YES];   [picker.view removeFromSuperview];

}

0

eApp .

1: MessageUI.

2. .h,   #import "MessageUI/MessageUI.h". MFMailComposeViewControllerDelegate, , UIViewController * emailMe;

Step 3: In the .m file, add these lines of code to 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 to .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 application :)

0
source

Source: https://habr.com/ru/post/1717731/


All Articles