Why doesn't my Cordova/PhoneGap iOS app rotate when the device rotates?
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.
Cordova: screen not rotating
I just had a view to the newest config.xml doc at
https://cordova.apache.org/docs/en/5.4.0/config_ref/index.html
For Android devices you need:
<platform name="android">
<preference name="Orientation" value="sensorLandscape" />
</platform>
and for iOS:
<platform name="ios">
<preference name="Orientation" value="all" />
</platform>
and BlackBerry:
<preference name="Orientation" value="landscape" />
But there is no doc about Windows.
Prevent 180 degree flip iOS Cordova
You can disable this by unchecking the upside down
orientation in Xcode.
Cordova iOS landscape orientation
I finally did it. The trick was just to put the custom .plist file in the res/native//-Info.plist.
This link gave me the solution: Tools for Apache Cordova (VS2015): Adding custom entries to *info.plist for iOS
Phonegap page has wrong rotation, shows as portrait in landscape mode
You can check the root Controller - shouldAutorotateToInterfaceOrientation, allow rotation for certain orientation. Hope it helps.
For example return true
in Classes/MainViewController.m
:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return true;
}
ios phonegap black bar after orientation change
Another solution is to simply reload the page on orientation change. The phonegap browser adapts the zoom.
var originalPageLoadOrientation = window.orientation;
$(window).on("orientationchange", function() {
// just to avoid initial orientationchange which is called on page load
if (originalPageLoadOrientation==window.orientation) return;
location.reload();
});
This of course may have other implications in the app. (e.g if the app is a complex single page application where reloading the whole page restarts everything).
Edit: Instead of location.reload();
a better way is to do location.href = location.href;
. The latter seems to avoid a visible flashing of the display.
Related Topics
Looping Through Nsattributedstring Attributes to Increase Font Size
Autolayout Link Two Uilabels to Have the Same Font Size
Once Jailbroken, Will iOS Apps Run with Root Privilege
Automatically Adjustable View Height Based on Text Height in Swiftui
Uitableview Inside Uiscrollview Not Receiving First Tap After Scrollling
Enable Application Cache in Wkwebview
Swift Version of Componentsseparatedbystring
Handling Push Notifications When App Is Terminated
Convert an iOS Objective C Object to a JSON String
How to Get Image Metadata in iOS
Storyboard View Elements Greyed Out
How to Use a Custom Font with Dynamic Text Sizes in iOS7
Ios: Pre Install Ssl Certificate in Keychain - Programmatically
Ios: Frame.Size.Width/2 Doesn't Produce a Circle on Every Device