IPhone screen orientation does not change in cordova 3.5.0

When I rotate the screen in my application using the iPhone, it always remains in the portrait and nothing changes. However, it works great for the iPad. I can rotate it and change the orientation.

How to change the screen orientation of the application on the iPhone when it is turned on?

In config.xml I have:

<preference name="Orientation" value="default" />

The only solution I could find was to change the shouldAutorotateToInterfaceOrientation method in MainViewController.m inside the cordova code:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
--    return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
++    return true;
}

But this seems like an ugly solution for me, and I really would like to find a normal way to do this.

iPad iPhone iPhone, portraitUpsideDown, , .

- iPhone ? , .

+4
3

, , , .

<preference name="Orientation" value="default" />

UISupportedInterfaceOrientations iOS (/platform/ios/~app_name~/~app_name~.plist), :

  • "UIInterfaceOrientationLandscapeLeft";
  • "UIInterfaceOrientationLandscapeRight";
  • "UIInterfaceOrientationPortrait"; ( )
  • "UIInterfaceOrientationPortraitUpsideDown"

, config.xml plist, . , , , , .

, , ~ app_name ~.plist , . Xcode, .

, . , , .

+4

XCode, PListBuddy , cordova build ios, PList. - config.xml PList, , .

: .plist ?

#Grabs info from plist
plist=$SRCROOT"/"$INFOPLIST_FILE
orientations=`/usr/libexec/PlistBuddy -c "Print :UISupportedInterfaceOrientations" "$plist"`

#And changes it before writing out the plist again
if [ "$orientations" ]
then
/usr/libexec/PlistBuddy -c "Delete :UISupportedInterfaceOrientations array" "$plist"
fi
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations array" "$plist"
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations:0 string \"UIInterfaceOrientationPortrait\"" "$plist"
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations:0 string \"UIInterfaceOrientationPortraitUpsideDown\"" "$plist"
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations:0 string \"UIInterfaceOrientationLandscapeLeft\"" "$plist"
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations:0 string \"UIInterfaceOrientationLandscapeRight\"" "$plist"

, , .

+2

I created a hook file linking to it: fooobar.com/questions/702078 / ...

#!/usr/bin/env node

var fs = require('fs');
var plist = 'platforms/ios/<app-name>/<app-name>-Info.plist';

var iphoneModes = [
    "UIInterfaceOrientationLandscapeLeft",
    "UIInterfaceOrientationLandscapeRight",
    "UIInterfaceOrientationPortrait"
];

var ipadModes = [
    "UIInterfaceOrientationLandscapeLeft",
    "UIInterfaceOrientationLandscapeRight"
];

function getOrientationModeStr(modes) {
    var s = "<key>$1</key>\n\t<array>\n\t";
    modes.forEach(function(mode, index) {
        s += "\t<string>"+mode+"</string>\n\t";
    });
    return s;
}

if (fs.existsSync(plist)) {
    var p = fs.readFileSync(plist, 'utf8');
    // replace iphone modes
    p = p.replace(
        /<key>(UISupportedInterfaceOrientations)<\/key>[\r\n ]*<array>[\s\S]*?(?=<\/array>)/ig,
        getOrientationModeStr(iphoneModes)
    );
    // replace ipad modes
    p = p.replace(
        /<key>(UISupportedInterfaceOrientations~ipad)<\/key>[\r\n ]*<array>[\s\S]*?(?=<\/array>)/ig,
        getOrientationModeStr(ipadModes)
    );
    fs.writeFileSync(plist, p, "utf8");
}

hope this helps.

0
source

All Articles