Showing posts with label e-mail. Show all posts
Showing posts with label e-mail. Show all posts

Monday, 3 June 2013

How to implement e-mail view - Landscape: cocos2d


// in .h File //

    #import <MessageUI/MFMailComposeViewController.h>
       
    @interface Game : CCLayer <MFMailComposeViewControllerDelegate>
    {
        NSString *emailTitle;
        NSString *emailBody;
        UIImage *emailImage;
        MFMailComposeViewController *picker;
    }
    -(void)showMailPicker;
    -(id)initWithTitle:(NSString *)title body:(NSString *)body image:(UIImage *)image;
     
    // in .m File //

       
    -(id)initWithTitle:(NSString *)title body:(NSString *)body image:(UIImage *)image
    {
        self = [super init];
        if (self != nil) {
            emailTitle = title;
            emailBody = body;
            emailImage = image;
            [self showMailPicker];
        }
        return self;
    }
       
    -(void)showMailPicker
    {
        picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;
        picker.modalPresentationStyle = UIModalPresentationFullScreen;
        picker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
           
        [picker setSubject:emailTitle];
        [picker setMessageBody:emailBody isHTML:YES];
        picker.navigationBar.barStyle = UIBarStyleBlack;
           
        [[CCDirector sharedDirector] pause];
        UIViewController *rootViewController = (UIViewController *)[[[CCDirector sharedDirector] openGLView ] nextResponder];  // This will do it
           
        [rootViewController presentModalViewController:picker animated:YES];
        [picker release];
    }
       
    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
    {
        [[CCDirector sharedDirector] resume];
        [controller dismissModalViewControllerAnimated: YES];
    }
       

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.................... ;)