I’m using cocos2d-x framework and I need to popup the mail when clicking a button.
The code works fine on iphone5 (6.0), ipod touch 5(6.0):
MailSender.h
@interface MailSender : UIViewController <MFMailComposeViewControllerDelegate> { UIViewController *currentModalViewController; } -(void)sendMail:(const char *)subject receiver:(const char *)receiver; @end
MailSender.mm
` #import “MailSender.h”
#import “…/cocos2dx/platform/ios/EAGLView.h”
@implementation MailSender
- (void)sendMail:(const char *)subject receiver:(const char *)receiver
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:[NSString stringWithUTF8String:subject]];
NSArray *toRecipients = [NSArray arrayWithObject:[NSString stringWithFormat:@"%s", receiver]];
[mailer setToRecipients: toRecipients];
NSString *emailBody = @"";
[mailer setMessageBody:emailBody isHTML:YES];
UIViewController* rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
currentModalViewController = [UIViewController alloc];
[rootViewController.view addSubview:currentModalViewController.view];
[currentModalViewController presentViewController:mailer animated:true completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
const char *message;
switch (result)
{
case MFMailComposeResultCancelled:
message = "Mail cancelled";
break;
case MFMailComposeResultSaved:
message = "Mail saved";
break;
case MFMailComposeResultSent:
message = "Mail send";
break;
case MFMailComposeResultFailed:
message = "Mail failed";
break;
default:
message = "Mail cancelled";
break;
}
NSLog(@"%s",message);
[currentModalViewController dismissViewControllerAnimated:true completion:nil];
[currentModalViewController.view.superview removeFromSuperview];
[currentModalViewController release];
}
@end`
But on my ipad mini (6.0) the mail popped up correctly but when I clicked the “send mail” or “cancel” button the view was removed and leaving a black screen (everything on the screen is gone)
Any advice will be appreciated, thanks