How can I display mail composer in landscape mode by using MFMailComposeViewController in cocos2d? - cocoa-touch

I am writing a game in cocos2d. I want to add MFMailComposeViewController to the scene.
So, when I touch a CcLabel in the scene the mail sheet is opened.
#interface EmailScene : CCScene <MFMailComposeViewControllerDelegate>
{
MFMailComposeViewController *picker;
}
-(void)displayComposerSheet;
#end
#implementation EmailScene
- (id) init {
self = [super init];
if (self != nil) {
[self displayComposerSheet];
}
return self;
}
-(void)displayComposerSheet
{
[[CCDirector sharedDirector] pause];
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObject:#"srikanth.rongali786#gmail.com"];
[picker setToRecipients:toRecipients];
[[[CCDirector sharedDirector] openGLView] addSubview:picker.view];
[[CCDirector sharedDirector] stopAnimation];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[[CCDirector sharedDirector] resume];
CCScene *Scene = [CCScene node];
CCLayer *Layer = [GameWinScreen node];
[Scene addChild:Layer];
[picker.view removeFromSuperview];
[[CCDirector sharedDirector] startAnimation];
[picker dismissModalViewControllerAnimated:YES];
[[CCDirector sharedDirector] replaceScene:Scene];
}
#end
alt text http://www.freeimagehosting.net/uploads/4a77b9ceb9.png
But, the problem is my game is in landscape mode. So, I need the mail sheet to display in landscape mode. But, here the mail sheet is displayed in portrait mode. And the keyboard is appearing in landscape mode. But, the mail composure sheet is in portrait mode.
And how can we change the "sent from my iPhone" to "Sent From My iPad"
Thank you.
alt text http://www.freeimagehosting.net/uploads/3eb39ea1de.png

You can try to manually rotate view...:
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
[picker.view setTransform:landscapeTransform];

You can make your own mailcomposer that is derived from MFMailComposeViewController and you can overwrite only the function shouldAutorotateToInterfaceorientation.
I didn't try this, just give you an idea.

Who is managing your EmailScene object? If you have followed the MVC pattern, try present the MFMailComposeViewController object using the viewController of EmailScene view. This will work provided you have supported all orientations in the view controller.
Use:
-(void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
Instead of adding the MFMailComposeViewController's view as a subview.
Edit: Try to present the MFMailComposeViewController using the root view controller.

Related

Why do my touch event not work?

I have declared a void touchesbegan method in my controller but it doesn't work! i don't know why. i have an image view which i plan to click it to move to next controller. so i set the touches began method. i have linked the image view in the xib file but when i click the image. nothing happens. Please help, Thanks.
ViewController.h
#import <UIKit/UIKit.h>
#interface imageViewViewController : UIViewController
{
IBOutlet UIImageView *testing;
}
#property(nonatomic, retain) IBOutlet UIImageView *testing;
#end
ViewController.m
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if(touch.view == testing)
{
TestViewController *testviewcontroller = [[TestViewController alloc]initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:testviewcontroller animated:YES];
}
}
#end
P.S.
here i tried another method using tap gestures.
testing is the name of my image view. as u can see i comment out the ns log in the imagedidtapped method. it works til that point. however when i tried to navigate it out to another page it fails.
- (void)viewDidLoad
{
UITapGestureRecognizer *tapRecognizer;
[testing setTag:0];
[testing setUserInteractionEnabled:TRUE];
tapRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(imageViewDidTapped:)] autorelease];
tapRecognizer.numberOfTapsRequired = 1;
[testing addGestureRecognizer:tapRecognizer];
[self.view addSubview:testing];
[testing release];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)imageViewDidTapped:(UIGestureRecognizer *)aGesture {
UITapGestureRecognizer *tapGesture = (UITapGestureRecognizer *)aGesture;
UIImageView *tappedImageView = (UIImageView *)[tapGesture view];
switch (tappedImageView.tag) {
case 0:
//NSLog(#"UIImageView 1 was tapped");
[self navigate];
break;
case 1:
NSLog(#"UIImageView 2 was tapped");
break;
default:
break;
}
}
-(void)navigate
{
TestViewController *testviewcontroller = [[TestViewController alloc]initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:testviewcontroller animated:YES];
}
The problem is that by default userInteractionEnabled is NO for a UIImageView so you won't get any touches. Set it to YES.
Also the message handling for touchesBegan is really complicated. You'll be much happier if you attach a UITapGestureRecognizer to the image view.
EDIT: Now you say your touches handling is working, but the navigation is not taking place. So let's concentrate on this part of your code:
-(void)navigate
{
TestViewController *testviewcontroller = [[TestViewController alloc]initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:testviewcontroller animated:YES];
}
Put logging in there to make sure navigate is being called! If it isn't being called, you need to figure out why your other code is not running and calling it. If it is being called, then the problem is probably that self.navigationController is nil, i.e. you are not inside a navigation interface to start with.

Bugged Game Center Matchmaker appearance

I am developing multiplayer for my game and I have encountered following issue
I am using Cocos 2d 2.1 , iOS 6 and following code to show matchmaker (Landscape orientation)
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[[GCHelper sharedInstance] findMatchWithMinPlayers:2 maxPlayers:4 viewController:[app navController] delegate:self];
And thats how it appears
Following code is used for that function
- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers
viewController:(UIViewController *)viewController
delegate:(id<GCHelperDelegate>)theDelegate {
if (!gameCenterAvailable) return;
matchStarted = NO;
self.match = nil;
self.presentingViewController = viewController;
delegate = theDelegate;
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;
GKMatchmakerViewController *mmvc =
[[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentViewController:mmvc animated:YES completion:nil];
}
is this code in HelloWorldLayer? if so is that the first layer that the director calls? I have the same problem but it's fixes if I follow strictly the cocos2d template that was created for me. Meaning that I use the IntroLayer as the initial layer and from there it transitions into the HelloWorldLayer where I have the game center code. I think it has something to do with the director being loaded too late but I'm not sure
This happens when you try to push on a UIViewController, but you only have a UIView in your app, and no UIViewController. Let me guess, you do not have a rootViewController.
If you are working from the EAGLView template, you must declare a UIViewController for the UIView. This can be as simple as,
- (void) applicationDidFinishLaunching:(UIApplication *)application
{
window.rootViewController = [[UIViewController alloc] init];
window.rootViewController.view = glView; // MUST SET THIS UP,
// NOW THE EAGLView HAS A UIViewController.
[glView startAnimation];
}
Then, anytime you want to push on one of those GameKit UIViewControllers, use the presentViewController method of your Window object's rootViewController
For example:
[self.window.rootViewController presentViewController:vc animated:TRUE completion:^(void){puts("DONE");} ] ;
The bugginess will go away and the window will be correctly formed.

presentModalViewController:picker not working in iPad MFMailComposeViewController

i am using the following code for the mail composer sheet in iPad application. I used the same code for iPhone. It worked.
I am writing the game in iPad using cocos2d. The game is in landScape mode. The control in EmailScene is stopping at [picker presentModalViewController:picker animated:YES]; It is not giving any error. Should I change my code for iPad ?
#interface EmailScene : CCScene <MFMailComposeViewControllerDelegate>
{
MFMailComposeViewController *picker;
}
-(void)displayComposerSheet;
#end
#implementation EmailScene
- (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
{
[[CCDirector sharedDirector] pause];
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
//Fill in the email as you see fit
NSArray *toRecipients = [NSArray arrayWithObject:#"srikanth.rongali786#gmail.com"];
[picker setToRecipients:toRecipients];
//display the view
[[[CCDirector sharedDirector] openGLView] addSubview:picker.view];
[[CCDirector sharedDirector] stopAnimation];
//When I commented the following two lines the mail page is opening.
//[picker presentModalViewController:picker animated:YES];
//[picker release];
}
But, the problem is my game is in landscape mode and the mail sheet is displayed in portrait mode.
Thank you.
You are using -presentModalViewController:… wrongly. This method should be called on the topmost view controller before the "picker" is presented.
[topmostViewController presentModalViewController:picker animated:YES];
(You shouldn't add picker.view as a subview of the -openGLView either.)

Loading an OverlayView from XIB -vs- programmatically for use with UIImagePickerController

I am currently making a camera app for iPhone and I have a strange phenomenon that I can't figure out. I would appreciate some help understanding.
When recreating an overlay view for passing to UIImagePickerController, I have been successfully been able to create the view programmatically. What I haven't been able to do is create the view with/without controller in IB, load it and pass it to the overlay pointer successfully. If I do it via IB, the view is not opaque and obscures the view of the camera completely. I can not figure out why.
I was thinking that the normal view pointer might be assigned when loading from XIB and therefore overwrite the camera's view, but I have an example programmatically where view and overlayView are set equal in the controller class. Perhaps the load order is overwriting a pointer?
Help would be appreciated... kind regards.
This works fine...
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// dislodge the MainView from the MainViewController
//
MainViewController *aController = [[MainViewController alloc] init]; //WithNibName:#"MainView" bundle:nil];
aController.sourceType= UIImagePickerControllerSourceTypeCamera;
aController.delegate= aController;
aController.showsCameraControls= NO;
// Programmatically load the MainView from the Nib and assign it as the OverlayView instead
//
NSArray* nibViews= [[NSBundle mainBundle] loadNibNamed:#"MainView" owner:aController options:nil];
UIView* uiView= [nibViews objectAtIndex:0];
uiView.opaque= NO;
uiView.backgroundColor= [UIColor clearColor];
aController.cameraOverlayView= uiView;
self.mainViewController = aController;
[aController release];
mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[window addSubview:[mainViewController view]];
[window makeKeyAndVisible];
}
This DOESN'T...
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// dislodge the MainView from the MainViewController
//
MainViewController *aController = [[MainViewController alloc] initWithNibName:#"MainView" bundle:nil];
aController.sourceType= UIImagePickerControllerSourceTypeCamera;
aController.delegate= aController;
aController.showsCameraControls= NO;
aController.cameraOverlayView= aController.view;
self.mainViewController = aController;
[aController release];
mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[window addSubview:[mainViewController view]];
[window makeKeyAndVisible];
}

UIViewController dismissModalViewControllerAnimated: causes main window to disappear

I want to present a modal mail dialogue like so in the iPad app:
MFMailComposeViewController* picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:title];
[picker setMessageBody:[NSString stringWithFormat:[self emailBody], title, [link absoluteString]] isHTML:YES];
[self.viewController presentModalViewController:picker animated:YES];
The following delegate is called when the user sends/cancels:
- (void) mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self.viewController dismissModalViewControllerAnimated:YES];
}
This works great in portrait mode. In landscape mode the right hand pane of the UISplitViewController completely disappears.
You can only present these from the primary view of your application. In this case, presenting from the UISplitViewController works.