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];
    }
       

No comments:

Post a Comment