Monday, 3 June 2013

How to implement e-mail view - Portrait: cocos2d

// in .h File //

    #import <MessageUI/MessageUI.h>
   
    @interface EmailScene : CCLayer <MFMailComposeViewControllerDelegate>
    {
        UIViewController * emailMe;
    }



// in .m File //

    #import "EmailScene.h"

    -(id) init
    {
        if( (self=[super init])) {
               
        CCMenuItemImage *Button_1 = [CCMenuItemImage
                                    itemFromNormalImage:@"Icon-72.png"
                                    selectedImage:@"i.png"
                                    target:self
                                    selector:@selector(emailCallback)];
               
        Button_1.position = ccp(160, 240);
               
        CCMenu *levelMenu = [CCMenu menuWithItems:Button_1, nil];
        levelMenu.position = ccp(0,0);
        [self addChild:levelMenu z:1];
               
               
        emailMe = [[UIViewController alloc] init];
        [[[CCDirector sharedDirector] openGLView] addSubview:emailMe.view];
               
        }
        return self;
    }
       
       
    -(void)emailCallback
    {
        [[CCDirector sharedDirector] pause];
        [[CCDirector sharedDirector] stopAnimation];
           
        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;
       
        NSArray *toRecipient = [NSArray arrayWithObject:@"krishnaraj@schogini.com"];
        [picker setToRecipients:toRecipient];
       
        [picker setSubject:@"Email test "];
        [picker setMessageBody:@"finally its working " isHTML:YES];
        picker.navigationBar.barStyle = UIBarStyleBlack;
           
        [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];
    }
       


This will do it.................... ;)

No comments:

Post a Comment