For Universal app: Portrait-only in iPhone but all orientations on iPad?

I’m building a universal app that needs to support all orientations on iPad but only portrait orientation on iPhone.

In XCode, I’ve set it as such, but the app is still supporting all orientations on iPhone. I’m not sure if this is because Corona’s build.settings (which don’t seem to allow device-specific orientation settings) are overriding the XCode settings, or something else.

There seems to be a couple old forum posts which reference the following syntax: 

settings.iphone.plist[“UIInterfaceOrientation~ipad”] = “UIInterfaceOrientationPortrait”

settings.iphone.plist[“UISupportedInterfaceOrientations~ipad”] = 

{ “UIInterfaceOrientationPortrait”,“UIInterfaceOrientationPortraitUpsideDown” } 

but those just seem to be manually setting the plist, which I’ve already done in Xcode, and I’m not sure if that syntax is supported by Corona anymore either.

Also, another old forum post by Rob suggested building separate versions of the app, but unfortunately that just isn’t a possibility since the app is paid.

Any help with this would be greatly appreciated!

I think I found a solution to this.

In build.settings, use the following settings for orientation:

[lua]

orientation = {

default = “portrait”,

content = “”,

supported = {

“portrait”,

“landscapeLeft”,

“landscapeRight”,

“portraitUpsideDown”

},

},

[/lua]

In Xcode, add the following method to AppCoronaDelegate.mm:

  • (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

        // iPad

        return UIInterfaceOrientationMaskAll;

    } else {

        // iPhone / iPod Touch

        return UIInterfaceOrientationMaskPortrait;

    }

    

}

 

Lastly, I don’t know if this really matters, but in XCode’s App Deployment Info, for iPhone I only checked “Portrait” for Device Orientation. And for iPad I checked all 4 Device Orientations.

There seems to be an issue with this method right now:

settings.iphone.plist[“UIInterfaceOrientation~ipad”] = “UIInterfaceOrientationPortrait”

settings.iphone.plist[“UISupportedInterfaceOrientations~ipad”] = { “UIInterfaceOrientationPortrait”,“UIInterfaceOrientationPortraitUpsideDown” } 

As far as i can see that doesn’t actually effect the iPad at all… I had to add this extra line of code to get it to start working:

settings.iphone.plist[“CoronaViewSupportedInterfaceOrientations~ipad”] = { “UIInterfaceOrientationPortrait”,“UIInterfaceOrientationPortraitUpsideDown” }

Hopefully that will save someone a bit of time…

I think I found a solution to this.

In build.settings, use the following settings for orientation:

[lua]

orientation = {

default = “portrait”,

content = “”,

supported = {

“portrait”,

“landscapeLeft”,

“landscapeRight”,

“portraitUpsideDown”

},

},

[/lua]

In Xcode, add the following method to AppCoronaDelegate.mm:

  • (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

        // iPad

        return UIInterfaceOrientationMaskAll;

    } else {

        // iPhone / iPod Touch

        return UIInterfaceOrientationMaskPortrait;

    }

    

}

 

Lastly, I don’t know if this really matters, but in XCode’s App Deployment Info, for iPhone I only checked “Portrait” for Device Orientation. And for iPad I checked all 4 Device Orientations.

There seems to be an issue with this method right now:

settings.iphone.plist[“UIInterfaceOrientation~ipad”] = “UIInterfaceOrientationPortrait”

settings.iphone.plist[“UISupportedInterfaceOrientations~ipad”] = { “UIInterfaceOrientationPortrait”,“UIInterfaceOrientationPortraitUpsideDown” } 

As far as i can see that doesn’t actually effect the iPad at all… I had to add this extra line of code to get it to start working:

settings.iphone.plist[“CoronaViewSupportedInterfaceOrientations~ipad”] = { “UIInterfaceOrientationPortrait”,“UIInterfaceOrientationPortraitUpsideDown” }

Hopefully that will save someone a bit of time…