- Home /
Auto-rotation on iPhone, forced landscape on iPad
I have a game and my publisher absolutely has to have portrait mode for the phone version, but we don't want to redesign everything for the iPad version, because portrait mode doesn't make sense for it. How can I have auto-rotation work for the iPhone, but lock it in landscape mode for the iPad?
And yes, I'm aware of the rotation settings in Player Settings, but they only let me choose either to have auto-rotation on or off. Also, I even tried disabling iPad portrait orientation in XCode after the Unity build and it still would rotate anyway on the iPad! Thanks for any help you can provide.
Answer by CodeElemental · Jun 24, 2016 at 11:57 AM
Check the implementation here : http://andrewstutorialblog.blogspot.mk/2014/12/disable-screen-auto-rotation-on-unity3d.html
As for the device detection, check this answer : http://answers.unity3d.com/questions/552549/check-is-iphone-or-ipad.html
Device detection, however, is no longer so simple. Here's the code I wrote for that:
bool IsIPad() {
UnityEngine.iOS.DeviceGeneration gen = UnityEngine.iOS.Device.generation;
return ( gen == UnityEngine.iOS.DeviceGeneration.iPad1Gen ||
gen == UnityEngine.iOS.DeviceGeneration.iPad2Gen ||
gen == UnityEngine.iOS.DeviceGeneration.iPad3Gen ||
gen == UnityEngine.iOS.DeviceGeneration.iPad4Gen ||
gen == UnityEngine.iOS.DeviceGeneration.iPadAir1 ||
gen == UnityEngine.iOS.DeviceGeneration.iPadAir2 ||
gen == UnityEngine.iOS.DeviceGeneration.iPad$$anonymous$$ini1Gen ||
gen == UnityEngine.iOS.DeviceGeneration.iPad$$anonymous$$ini2Gen ||
gen == UnityEngine.iOS.DeviceGeneration.iPad$$anonymous$$ini3Gen ||
gen == UnityEngine.iOS.DeviceGeneration.iPad$$anonymous$$ini4Gen ||
gen == UnityEngine.iOS.DeviceGeneration.iPadPro1Gen ||
gen == UnityEngine.iOS.DeviceGeneration.iPadPro10Inch1Gen ||
gen == UnityEngine.iOS.DeviceGeneration.iPad$$anonymous$$ );
}
Ouch, the technology debt with this one... Unfortunately there is no futureproof alternative.
Answer by Dani_Schenker · Feb 19 at 04:48 PM
1st reply helped, as far as coding is concerned, thx!
But to make it finally work with our iOS app (iPhones: portrait, iPad portrait AND landscape mode), we had to use the following Xcode and Unity settings: