Why doesn't my Cordova/PhoneGap iOS app rotate when the device rotates?
I am trying to make a landscape only app, but I am not able to produce any rotation at all.
There used to be a autorotate
setting in PhoneGap.plist
but in phonegap 1.8.0 I can find it. Does it still exists?
What else could be wrong that my application is not rotating?
UPDATE
I know have webpage containing only one word "test". I set target device to iPad only and enabled all four orientations. What could still be wrong?
Do need to have a special html document type? Do I need to include some cordova-1.8.0.js? I could not find one for iOS (!?!) so i tested it with the android version. I read the API is now the same so can I use the android .js file?
Solution 1:
I tried the JavaScript solution above and got no joy In Visual Studio 2015 I change the config.xml to
<preference name="orientation" value="all" />
taken from Cordova 5 build command is deleting iOS device orientation settings
I didn't need the javascript just the config setting
Solution 2:
PiTheNumber's answer looks OK for those fine with modifying the Cordova-generated native code.
Following this JIRA issue on Cordova, and as neatly explained in this blog, you can also use plist values or define a window.shouldRotateToOrientation function in your Javascript code, which suits me very well.
window.shouldRotateToOrientation = function(degrees) {
return true;
}
This would enable device orientation for the current page (so, for your whole app if it's a "one page app" as most Cordova apps are). Note you can also decide to enable it based on the rotation value in degrees, or even, why not, enable it only on certain views, or letting the user choose within your HTML app... Nice, isn't it.
For the record, I didn't need to do anything to get an iOS 8 iPad handle rotation, while both iOS 6 and iOS 7 iPhones wouldn't handle it by default in the current Cordova version (4.2.0, cordova ios platform version "ios 3.7.0"). That is because one can grant different rotation settings per "device type" (tablet / phone) on Xcode. The thing to note is that Cordova will first check the JS function above if it exists, and then if the function does not exist or it did not allow the rotation, the Xcode rotation setting will be used.