Issue with iPad app in Landscape mode

Hi,

I have an iPad app for iOS which I would like to work in both portrait and landscape mode but I have narrowed the issue down to being a problem specifically with landscape mode.

In the settings in xcode I have the device orientation set as follows (I realise these are connected to the orientation setting in config.xml but its quicker to debug directly in xcode):

So the problem is that if I launch the device in landscape mode, the app seems to be in the wrong orientation and also cut off like so:

If I rotate the device to portrait and then back to landscape, it corrects itself but obviously this is undesirable.

I have trawled the forums/google and have seen quite a few similar problems like this and this but have not seen a satisfactory solution.

Some info about my setup:

  1. Latest Ionic 1.2.0
  2. Ionic CLI 1.7.11
  3. Cordova ios 3.9.2
  4. Cordova CLI 5.4.1
  5. I’m on a mac (osX 10.10.3) running xcode 6.4
  6. Testing app on an iPad Mini (ios 8.1.2) but problem is also happening on an ipad air running ios 8.3
  7. My viewport meta tag looks like <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> but I have tried with a few variations and even no meta tag but it has no effect.

I have tried lots of different variations of <preference name="Orientation" value="landscape" /> and <preference name="Orientation" value="default" /> and <preference name="Orientation" value="all" /> in the config.xml.

The best solution I have got at the moment (Which @Gajotres suggested here) is to omit the <preference name="Orientation" /> tag completely and use the cordova screenorientation plugin to unlock the orientation. BUT there is one problem with this…

Now when I launch the device in landscape mode, although it fixes the weird cut-off effect. The app still seems to think it’s in portrait mode (i.e. same as previous screenshot, just without the black border and the buttons are further along to edge of the screen). I have to rotate the device to portrait and then back to landscape mode and it then corrects itself. Again not desirable.

I have been wrestling with this for quite a while now and don’t know where to go with this issue. I find it a bit strange that there is such a glaring problem with a supposedly trivial task of launching an ipad app in landscape mode which makes me think that I must be doing something wrong but it seems quite a few other people are having the same issue so I don’t know what to think.

Is anyone able to help solve this?

Thanks

@mhartington Do you have any insight into this issue? Thanks

I’m experiencing the same issue, sorry not to be of any help, but also awaiting a solution…

Yeah, its a bit of a blocker on my current project. Do let me know if you ever solve it.

Hey, I found a solution. I don’t know the root cause of why this issue occurred, but this hack will solve it.

It has to do with the splash screen plugin, in CDVViewController+SplashScreen.m.

- (BOOL)enabledAutorotation { NSNumber *number = (NSNumber *)objc_getAssociatedObject(self, @selector(enabledAutorotation)); return [number boolValue]; }

Debugging this, number is always nil. Why? I have no idea…but if I change this to:

- (BOOL)enabledAutorotation { //NSNumber *number = (NSNumber *)objc_getAssociatedObject(self, @selector(enabledAutorotation)); NSNumber *number = @1; return [number boolValue]; }

It works beautifully. Again, take this with a grain of salt, I don’t know what unintended consequences it will have, but I haven’t found any so far.

1 Like

@elli_wodify: You hero! This is a great workaround for me, thanks for reporting back! :smile:

It does seem to be a bug with the splashscreen plugin:
https://issues.apache.org/jira/browse/CB-9240

Off the back of that discussion, I am now using this forked plugin instead of the official cordova plugin until they fix the issue. The forked version comments out a whole block of code in the load method but it seems to be interconnected to your solution.

I still think there may be an issue with iPhone (especially iPhone 6 plus) in landscape mode, even with this workaround, but I need to fully device test before coming to any conclusions.

Anyway, thanks again!

1 Like

In case you haven’t seen, this was fixed in the official plugin about a week after we had this conversation, lol. The exact issue was that when number was nil, it should return YES, and as we know, it wasn’t.

Thank you for sharing pointers on this issue. We tried using the latest plugin and were still able to reproduce the issue.

Wish to ask you whether you were able to arrive at a good conclusion on the issue after updating the plugin.

Still able to reproduce the same error with latest plugins on iPhone 6 plus iOS 10.3.2.

cordova-plugin-splashscreen 4.0.0 "Splashscreen"

cordova-plugin-screen-orientation 1.4.2 "Screen Orientation"

Had tried to delete <preference name="Orientation" /> and used only plugin to control the orientations, later tried to set the orientation to the Landscape, neither methods had work. Also tried the work around from elli_wodify but the problem still occurred.