I am writing an app in using cocos2d. This method I have written for the selector goToFirstScreen: . The view is in landscape mode. I need
to send an email. So, I need
to launch the MFMailComposeViewController. I need it in portrait mode.
But, the control is not entering in
to viewDidLoad of the mailMe class. The problem is in goToScreen: method. But, I do not get where I am wrong ?
-(void)goToFirstScreen:(id)sender
{
NSLog(@"goToFirstScreen: ");
CCScene *Scene = [CCScene node];
CCLayer *Layer = [mailME node];
[Scene addChild:Layer];
[[CCDirector sharedDirector] setAnimationInterval:1.0/60];
[[CCDirector sharedDirector] pushScene: Scene];
}
This is my mailMe class
to launch mail controller
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import "cocos2d.h"
@interface mailME : CCLayer <MFMailComposeViewControllerDelegate>
{
UIViewController *mailComposer;
}
-(void)displayComposerSheet;
-(void)launchMailAppOnDevice;
@end
#import "mailME.h"
@implementation mailME
-(void)viewDidLoad
{
NSLog(@"Enetrd in
to mail");
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
if ([mailClass canSendMail])
{
[self displayComposerSheet];
}
else
{
[self launchMailAppOnDevice];
}
}
else
{
[self launchMailAppOnDevice];
}
}
-(void)displayComposerSheet
{
CCDirector *director = [CCDirector sharedDirector];
[director pause];
[director stopAnimation];
[director.openGLView setUserInteractionEnabled:NO];
mailComposer = [[UIViewController alloc] init];
[mailComposer setView:[[CCDirector sharedDirector]openGLView]];
[mailComposer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Hello!"];
NSArray *toRecipients = [NSArray arrayWithObject:@"
[email protected]"];
[picker setToRecipients:toRecipients];
NSString *emailBody = @"It is not working!";
[picker setMessageBody:emailBody isHTML:YES];
[mailComposer presentModalViewController:picker animated:NO];
[picker release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
case MFMailComposeResultCancelled:
break;
case MFMailComposeResultSaved:
break;
case MFMailComposeResultSent:
break;
case MFMailComposeResultFailed:
break;
default:
break;
}
[mailComposer dismissModalViewControllerAnimated:NO];
[[UIApplication sharedApplication] setStatusBarOrientation:CCDeviceOrientationLandscapeLeft animated:NO];
CCDirector *director = [CCDirector sharedDirector];
[director.openGLView setUserInteractionEnabled:YES];
[director startAnimation];
[director resume];
[mailComposer.view.superview removeFromSuperview];
}
-(void)launchMailAppOnDevice
{
NSString *recipients = @"mailto:
[email protected]?&subject=Hello!";
NSString *body = @"&body=It is not working";
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
- (void)dealloc
{
[super dealloc];
}
@end