Set Initial Device Orientation - Corona Native

Hi all,

I’ve been struggling with this one for a good 24 hours or so, Google is doing me no favours, and I’m at the end of my tether, so really hoping someone can help me out.

I’ve got a Corona Native app that I want to initially run in landscape-right as soon as it’s launched (iOS) - Launching an lua scene.

Now I can do this, simply in AppCoronaDelegate.mm:
 

-(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

        return UIInterfaceOrientationMaskLandscapeRight;

}

However I’m then locked to LandscapeRight

I have another part of my app written entirely in objective C (no lua), which needs to run in portrait

When I don’t use the above code in AppCoronaDelegate.mm I can set up a custom view controller for that part of the which automatically rotates to portrait:

    [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@“orientation”];

    [UIViewController attemptRotationToDeviceOrientation];

However, as soon as I add the above code to AppCoronaDelegate.mm this view controller is overridden.

While that’s expected behaviour of course, I’m now a bit stuck, AppCoronaDelegate is not accessible to my view custom view controller, and I seem to have no other way to set initial orientation.

One idea was to use the method from the view controller in AppCoronaDelegate, unfortunately this doesn’t work because AppCoronaDelegate appears to be called before my first (ideally landscape-right) scene, and therefore completely upsets the layout.

I’d look at rotating the whole lua scenes themselves, but they use native elements, plus the keyboard so this doesn’t work either.

HELP!

I really don’t know what to try any more, hopefully someone has come across something similar before and can suggest a workaround.

Many, many thanks in advance!

Paul 

Hello!

Corona have this method overloaded, and uses PList values from it. Usually, those values are injected from build.settings. Alternatively you can add them yourself.

Corona has [UIViewController supportedInterfaceOrientations] overloaded which gets values from plist. See https://docs.coronalabs.com/native/ios/index.html#setting-orientation

Hello!

Corona have this method overloaded, and uses PList values from it. Usually, those values are injected from build.settings. Alternatively you can add them yourself.

Corona has [UIViewController supportedInterfaceOrientations] overloaded which gets values from plist. See https://docs.coronalabs.com/native/ios/index.html#setting-orientation