Hassy31
Hassy31

Reputation: 2813

cocos2d orientation issues in ios<= 6

I developed a game supports only landscape mode for upper than ios 4.3 devices. the application has gamecenter implemented and crashed during the test on ios 6 devices because gamecenter login screen doesn't support landscape mode in ios 6. so I fixed the problem adding below code into appdelegate.m and got worked but now application displays totally wired(displays portrait upside down) on devices below ios6(ios5 etc)

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;
    else // iphone
        return UIInterfaceOrientationMaskAllButUpsideDown;
}

use xcode:4.5 cocos2d v1.0.1

please help me to solve this problem

Upvotes: 0

Views: 210

Answers (2)

iC7Zi
iC7Zi

Reputation: 1658

Replace this line of code [window addSubview: viewController.view]; with below one in AppDelegate.m

//************************************************************************
    NSString *reqSysVer = @"6.0";
    NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
    if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
    {
        [window setRootViewController:viewController];
    } else
    {
        [window addSubview: viewController.view];
    }
    //************************************************************************

And in RootViewController.m add below code

///////********************************/////////

// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead of shouldAutorotateToInterfaceOrientation

- (NSUInteger) supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL) shouldAutorotate {
    return YES;
}

///////********************************/////////

Upvotes: 0

Mohd Kalimullah Sheikh
Mohd Kalimullah Sheikh

Reputation: 363

Add given class in your project

GKMatchmakerViewController-LandscapeOnly.h

#import <Foundation/Foundation.h>
#import <GameKit/GameKit.h>

@interface GKMatchmakerViewController(LandscapeOnly)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
@end

GKMatchmakerViewController-LandscapeOnly.m


#import "GKMatchmakerViewController-LandscapeOnly.h"

@implementation GKMatchmakerViewController (LandscapeOnly)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );
}

@end

Upvotes: 1

Related Questions