Help adding mail view to my unity project

Hi everyone.

I’m beggining to experiment with native code in IOS I have succeed in adding an ImageView over my unity view, by simply doing this in my AppController:

UIImageView *myImage = [[UIImageView alloc] initWithFrame: _window.frame];
[myImage setImage:[UIImage imageNamed:@“test.png”]];
[_window insertSubview:myImage atIndex:[_window.subviews count]];
//[_window addSubview:myImage];
[myImage release];

But now i’m trying to send a mail, and after creating and adding the view with the next code it never appears:

MailHandler *mailDelegateObject= nil;
mailDelegateObject = [[MailHandler alloc] init];
[_window insertSubview:mailDelegateObject.view atIndex:[_window.subviews

count]];

Here’s the code of my delegate for mail:

//MailHandler.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

@interface MailHandler : UIViewController {
//@interface MFMailComposeViewControllerDelegate : NSObject {
IBOutlet UIButton *button;
}

  • (IBAction)actionEmailComposer;

@end

And the .mm:

// MailHandler.mm
#import “MailHandler.h”

//@implementation MFMailComposeViewControllerDelegate
@implementation MailHandler

  • (void)dealloc {
    [super dealloc];
    }

  • (id)init
    {
    self = [super init];
    NSLog(@“starts mailhandler”);
    return self;
    }

  • (IBAction)actionEmailComposer {

if ([MFMailComposeViewController canSendMail]) {

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@“Subject Goes Here.”];
[mailViewController setMessageBody:@“Your message goes here.” isHTML:NO];

[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];

}

else {

NSLog(@“Device is unable to send email in its current state.”);

}

}

  • (void)viewDidLoad {

//[super viewDidLoad];
if ([MFMailComposeViewController canSendMail])
button.enabled = YES;

}

  • (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

}

  • (void)viewDidUnload {

}

-(void)mailComposeController: (MFMailComposeViewController*)controller didFinishWithResult: (MFMailComposeResult)result error: (NSError*)error {
[self becomeFirstResponder];
[self dismissModalViewControllerAnimated:YES];
}

@end

Any help and suggestion is much appreciated, thanks !

Additionally, this is a correct approach to working with Unity and Xcode ?, by creating and adding/removing views whenever it’s needed ?, or there is any other better approach.

Edit: Problem solved.

Hi antikhaoz ,

I am new to unity and used cocos2d for a year . I making a project using unity and trying to integrate mail for ios . I have used the same native code as above and calling it from c# class from unity… i am getting control in my obj C class function composeMail (checked by printing there) but unable to see
compose mail window…
thanks in advance

Edit : problem solved .

Solution :

declare unity view controller …
UIViewController *UnityGetGLViewController();

Now , In actionEmailComposer function as stated in above post…

write [UnityGetGLViewController() presentModalViewController:composer animated:YES ];

instead of
[self presentModalViewController:mailViewController animated:YES];

also in mailComposeController function
write [UnityGetGLViewController() dismissModalViewControllerAnimated:YES];

instead of [self dismissModalViewControllerAnimated:YES];