Landscape App + ios 7.1.2 + cocos2d-x 3.3 + getWinSize

Hello,

I’ve been searching google for hours trying to find a solution. With ios 8.x, my app works perfectly in all situations. I’ve tested it on ipad air, ipad 2, 4, mini, mini non retina, iphone 4s, 5s, 6, & 6plus.

With ios 7.1, simulator or device, no matter what I do, getWinSize always returns portrait resolution. This of course causes my scene to scale and squish into the top left corner.

I’ve already got this in place:

// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
	// warning: addSubView doesn't work on iOS6
	[window addSubview: _viewController.view];
}
else
{
	// use this method on ios6
	[window setRootViewController:_viewController];
}

And these functions in my custom root view controller;

// Override to allow orientations other than the default portrait orientation.
// This method is deprecated on ios6

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }
  • (NSUInteger) supportedInterfaceOrientations{
    return(UIInterfaceOrientationMaskLandscape);
    }

Base SDK = 8.1
Xcode 6.1.1

I’ve even tried delaying the creation of my cocos2d-x scene using this from didfinishloadingwithoptions:

[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)    name:UIDeviceOrientationDidChangeNotification  object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

And creating my scene the first time I get an orientation message in “orientationChanged”.

I started doing it this way because with ios8, I was seeing problems that only when launching my app directly from inter-app-audio (garageband) I was also getting this width/height swap. Delaying it fixed it so that getwinsize returned landscape as expected. Until ios7 broke it…

Any ideas how I can get my landscape app to work under both ios7.x and ios8.x? Do I really need to do something like this? [SOLVED] Problem with coordinates and screen size in landscape orientation in iOS

When I had similar issues (a while ago now - so I don’t recall the details) I simply got the screen dimensions at the start of the app, and swapped them if H > W.

On mobile devices the size won’t change, so it only needs to be done once.