Hello everybody,
I have been looking into sending in app emails and thought I should write a summary of what I have found and ask for help with the last point I have not resolved.
Well first of all MessageUI.framework needs to be added to your project.
I have decided to display the email page in dedicated scene that is loaded from the menu with simply replacing the scene with the director.
EmailScene.h :
#import "cocos2d.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
@interface EmailScene : Scene <MFMailComposeViewControllerDelegate>
{
IBOutlet UILabel *message;
MFMailComposeViewController *picker;
}
@property (nonatomic, retain) IBOutlet UILabel *message;
-(void)displayComposerSheet;
@end
EmailScene.m :
#import "EmailScene.h"
#import "MenuScene.h"
@implementation EmailScene
@synthesize message;
- (id) init {
self = [super init];
if (self != nil) {
[self displayComposerSheet];
}
return self;
}
// Displays an email composition interface inside the application. Populates all the Mail fields.
-(void)displayComposerSheet
{
[[Director sharedDirector] pause];
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
//Fill in the email as you see fit
//display the view
[[[Director sharedDirector] openGLView] addSubview:picker.view];
[picker presentModalViewController:picker animated:YES];
[picker release];
}
// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[[Director sharedDirector] resume];
//return to previous scene
MenuScene * menuScene = [MenuScene node];
[[Director sharedDirector] replaceScene:menuScene];
//dismiss view after otherwise the code is not executed
[picker.view removeFromSuperview];
[picker dismissModalViewControllerAnimated:YES];
}
@end
With this code the email view is displayed and functional but when returning from it, either the view is not removed properly or the director has lost the current view in which to run.
The email view stays visible but the director runs the code from the menu scene (visible in the logs only).
I don't think I am missing much for this to work so any help would be appreciated.