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.plis
You can add UISupportedInterfaceOrientations
platroms/ios/{ProjectName}/{ProjectName-info.plist
add this rows:
For Iphone:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
For Ipad:
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
In Classes/MainViewController.m
return true:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return true;
}
For iOS >= 6
- (BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
Source
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
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.