Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make iOS rotate as needed when lockOrientation is called #101

Merged
merged 4 commits into from May 22, 2016

Conversation

@tony--
Copy link
Collaborator

commented Apr 22, 2016

Continue using ForceViewController approach but instead of immediately dismissing, first dynamically update supportedInterfaceOrientations on the main ViewController, then dismiss.
Only tested on iPhone 6 w/ iOS 9.2.1 so far.

@gbenvenuti

This comment has been minimized.

Copy link
Owner

commented Apr 23, 2016

Hi @tony--,

Thanks for the PR, I'll run some further tests in the next day and merge this into a dev branch for testing by some of the users who have reported issues. I only have the simulator to test on.

@gbenvenuti

This comment has been minimized.

Copy link
Owner

commented Apr 25, 2016

Hi @tony-- ,

Looks to be working well for the lock functionality after adding the plugin.xml links cbab424

The simulator at least however does not respond to the unlockOrientation call, i.e. it stays in previous locked state.

@tony--

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 26, 2016

I'll try to get unlock working today.

@arendjantetteroo

This comment has been minimized.

Copy link

commented Apr 26, 2016

I've tried this as a fix for the orientatiochange event no longer being fired on iphone 5 IOS 9.3.1, but that's not resolved (yet?).

@tony--

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 26, 2016

@arendjantetteroo - this only fixes the device automatically rotating when lockOrientation is called, it doesn't fix anything with orientationchange event.

@tony--

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 26, 2016

@gbenvenuti Whoops, sorry about the files missing from plugin.xml! I updated my branch with this change.
With regard to unlockOrientation, I tried this on simulator and it responded to unlockOrientation in my testing. Maybe my test is not correct?
My test app is just the default cordova-ios@4.1.1 template with the tony--:fix-ios-rotate-on-lock version of the plugin added.
cordova create screen-orientation-test
cd screen-orientation-test
cordova platform add ios@4.1.1
cordova plugin add https://github.com/tony--/cordova-plugin-screen-orientation#fix-ios-rotate-on-lock
I issued the following commands in the Safari remote web inspector console to test this:
screen.lockOrientation('landscape') //simulator rotates to landscape
screen.unlockOrientation() //simulator rotates back to portrait
Please let me know if you are seeing something different or if I am testing this incorrectly.
Thanks!

@bau720123

This comment has been minimized.

Copy link

commented May 1, 2016

hi @tony--
I did a test
but still not work in iOS
I am using...
cordova 6.1.1 + ios@4.1.1 + https://github.com/tony--/cordova-plugin-screen-orientation#fix-ios-rotate-on-lock + ipad mini 9.3.1 (real device not simulator)
screen.lockOrientation('no mater which value is')

@tony--

This comment has been minimized.

Copy link
Collaborator Author

commented May 4, 2016

@bau720123 - thanks for testing. It's working for me on:
cordova 6.1.1 + ios@4.1.1 + real iPhone 6 w/ iOS 9.3.1 + my branch

I wonder if iPad makes a difference? I'll test on iPad and give an update.

@tony--

This comment has been minimized.

Copy link
Collaborator Author

commented May 5, 2016

@bau720123
cordova 6.1.1 + ios@4.1.1 + iPad mini w/ iOS 9.3.1 + my branch
is working for me

My demo app starts in portrait
screen.lockOrientation('landscape') //rotates to landscape left, tilting rotates to landscape right, does not allow portrait
screen.unlockOrientation() //rotates to 'natural' orientation

Edit: I'll retest with a fresh demo app and include complete steps to reproduce - I'd like to understand why it is working for me but not for you.

@bau720123

This comment has been minimized.

Copy link

commented May 5, 2016

thanks @tony--
I think maybe we can compare the .plist file between yours and mine
maybe the "UISupportedInterfaceOrientations" and "UISupportedInterfaceOrientations~ipad" is the sticking point ?
my ipad mini is iPad2,5

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>Taiwan</string>
    <key>CFBundleDisplayName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    <key>CFBundleIcons</key>
    <dict/>
    <key>CFBundleIcons~ipad</key>
    <dict/>
    <key>CFBundleIdentifier</key>
    <string>com.littlebau.phonegap</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleLocalizations</key>
    <array>
      <string>zh_TW</string>
      <string>en</string>
    </array>
    <key>CFBundleName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>6.1011</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>6.1011</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSMainNibFile</key>
    <string/>
    <key>NSMainNibFile~ipad</key>
    <string/>
    <key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIRequiresFullScreen</key>
    <true/>
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
      <key>NSExceptionDomains</key>
      <dict>
        <key>m.facebook.com</key>
        <dict/>
        <key>graph.facebook.com</key>
        <dict/>
        <key>api.facebook.com</key>
        <dict/>
        <key>fbcdn.net</key>
        <dict>
          <key>NSIncludesSubdomains</key>
          <true/>
        </dict>
        <key>akamaihd.net</key>
        <dict>
          <key>NSIncludesSubdomains</key>
          <true/>
        </dict>
        <key>accounts.google.com</key>
        <dict/>
      </dict>
    </dict>
    <key>UIInterfaceOrientation</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This app will now only track your location when the screen is on and the app is displayed.</string>
    <key>FacebookAppID</key>
    <string>197653916921532</string>
    <key>FacebookDisplayName</key>
    <string>小包直覺設計</string>
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>fb197653916921532</string>
        </array>
      </dict>
      <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>com.littlebau.phonegap</string>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>com.littlebau.phonegap</string>
        </array>
      </dict>
      <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>REVERSED_CLIENT_ID</string>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>com.googleusercontent.apps.909119150051-0g74v62g7ifqf1qflvejg1lvf62ih16j</string>
        </array>
      </dict>
    </array>
    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>fbapi</string>
      <string>fb-messenger-api</string>
      <string>fbauth2</string>
      <string>fbshareextension</string>
      <string>com.littlebau.phonegap</string>
      <string>com.googleusercontent.apps.909119150051-0g74v62g7ifqf1qflvejg1lvf62ih16j</string>
      <string>com-google-gidconsent</string>
      <string>com-google-gidconsent-google</string>
      <string>com.google.gppconsent.2.4.0</string>
      <string>com.google.gppconsent.2.4.1</string>
      <string>citymapper</string>
      <string>comgooglemaps</string>
      <string>navigon</string>
      <string>transit</string>
      <string>waze</string>
      <string>yandexnavi</string>
      <string>uber</string>
      <string>tomtomhome</string>
      <string>twitter</string>
      <string>fb</string>
      <string>whatsapp</string>
    </array>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>This app requires constant access to your location in order to track your position, even when the screen is off.</string>
    <key>UIBackgroundModes</key>
    <array>
      <string>remote-notification</string>
    </array>
    <key>GCM_SENDER_ID</key>
    <string>909119150051</string>
    <key>IS_GCM_ENABLED</key>
    <true/>
  </dict>
</plist>
@tony--

This comment has been minimized.

Copy link
Collaborator Author

commented May 5, 2016

@bau720123 Based on your .plist, it looks like you have <preference name="Orientation" value="all"/> in your config.xml. In my test, I had not included any Orientation preference.
I added <preference name="Orientation" value="all"/> to the config.xml and did cordova prepare ios, resulting in the following entries being added to my .plist:

    <key>UIInterfaceOrientation</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationLandscapeRight</string>
    </array>

This seems to match what you have, but my simple test still works.

Could you try with a clean app?
I'd like to make sure we get the same behavior with the simplest case before digging into your app more.

cordova create screen-orientation-test
cd screen-orientation-test
cordova platform add ios@4.1.1
cordova plugin add https://github.com/tony--/cordova-plugin-screen-orientation#fix-ios-rotate-on-lock
cordova run ios

The test app should start in portrait and not auto-rotate.
Using Safari Web Inspector Console

screen.lockOrientation('landscape') 
//should rotate to landscape left and should auto-rotate between landscape orientations
screen.unlockOrientation()
//should rotate to portrait and no longer auto-rotate when device is tilted
@bau720123

This comment has been minimized.

Copy link

commented May 5, 2016

hi @tony--
yes
if I use a blank app,seem to work perfect
but still don't know why my original app won't work
I will trace it down and tell you why...

@tony--

This comment has been minimized.

Copy link
Collaborator Author

commented May 5, 2016

Thanks @bau720123. FWIW, I don't think it is any of your .plist settings - I tried dropping all of the relevant settings from your .plist into my test app in the same order and it still works.
It seems like it must be another plugin or another preference in config.xml.
Are you specifying deployment-target?

@bau720123

This comment has been minimized.

Copy link

commented May 6, 2016

hi @tony--
in my config.xml,my deployment-target is 8.0
I think it could be my problem,but I can't find what the problem is for now (maybe a webpage meta setting ?)
anyway,I will searching for this
if anything find,I will feedback to you
thanks again

@bau720123

This comment has been minimized.

Copy link

commented May 7, 2016

hi @tony--
find the problem is
thanks
anyway...my fault...

so...maybe release a new version to the NPM ?
https://www.npmjs.com/package/cordova-plugin-screen-orientation

@dbpieter

This comment has been minimized.

Copy link

commented May 11, 2016

What's the status of this pr ? Any update on this ?

@AG914

This comment has been minimized.

Copy link

commented May 13, 2016

The screen.unlockOrientation() doesn't work with ios@4.1.1 but works with ios@3.9.2.

cordova create screen-orientation-test
cd screen-orientation-test
cordova platform add ios@4.1.1
cordova plugin add https://github.com/tony--/cordova-plugin-screen-orientation#fix-ios-rotate-on-lock

Added <preference name="Orientation" value="all"/> in the config.xml

And

cordova prepare ios
cordova run ios

Rotate the device, It works perfect. Now, open the Safari Web Inspector Console

screen.lockOrientation('portrait')

And rotate the device, the rotate is lock, It work.

Go the Safari Web Inspector Console

screen.unlockOrientation()

And rotate the device, the unlock doesn't work.

Go your terminal and

cordova platform remove ios
cordova platform add ios@3.9.2
cordova run ios

Rotate the device, It works perfect. Now, open the Safari Web Inspector Console

screen.lockOrientation('portrait')

And rotate the device, the rotate is lock, It work.

Go the Safari Web Inspector Console

screen.unlockOrientation()

And rotate the device, the rotate is unlock, It work.

@tony--

This comment has been minimized.

Copy link
Collaborator Author

commented May 16, 2016

@AG914 Quick summary, a specific non-working case has been identified: with iOS@4.1.1 and an app with Orientation:All, locking orientation to portrait and then unlocking does not work as expected.

I was able to reproduce this issue - will look into it today.

@tony--

This comment has been minimized.

Copy link
Collaborator Author

commented May 16, 2016

@AG914 Thanks for testing! Sorry, I should have said as much in my last comment.

I just pushed a change that should fix the issue you reported.
In a nutshell, this change makes the plugin remember the original orientations that were allowed before any locking is done. When the orientation is unlocked, the allowed orientations are reverted to the original. This should allow interoperability between the Orientation preference and this plugin.

@tony-- tony-- force-pushed the tony--:fix-ios-rotate-on-lock branch from aba1098 to 9375778 May 16, 2016

@tony--

This comment has been minimized.

Copy link
Collaborator Author

commented May 16, 2016

Rebased onto latest from master to resolve conflicts

@AG914

This comment has been minimized.

Copy link

commented May 17, 2016

Work perfect. Thanks @tony--

@markarupert

This comment has been minimized.

Copy link

commented May 20, 2016

So did you post this to the 1.4 release. My iOS app is not locking the orientation with the 1.4.0 version. I tried using https://github.com/tony--/cordova-plugin-screen-orientation#fix-ios-rotate-on-lock and it was locking but did not seem to unlock. I removed the fix and tried adding it again but the fix-ios-rotate-on-lock on tony seems to be gone now.

Thanks,
Mark

@gbenvenuti gbenvenuti merged commit 9375778 into gbenvenuti:master May 22, 2016

@vetri50ster

This comment has been minimized.

Copy link

commented Feb 24, 2017

In my App, I have installed the "apache/cordova-plugin-screen-orientation" and I have set screen.orientation.lock('landscape'); to Lock Landscape view. But at first time in IPad (ios@10), If the user view in portrait view once "screen.orientation.lock('landscape');" is called it is not rotate to landscape view instead of that it stay in portrait view. But in other device it is working as excepted. How to get rid of this issue.When i can expect the updated release.

@dsl101

This comment has been minimized.

Copy link

commented Apr 24, 2017

I'm seeing a similar issue - I wonder if this has broken again since an iOS update or something?

Symptoms are that the lock 'works', but only after the user manually rotates the device. Testing on an iPhone 6 running 10.3.1

@freddyz

This comment has been minimized.

Copy link

commented May 2, 2017

version 2.0.1 of cordova-plugin-screen-orientation fixed the iOS issue for me. Now when screen.orientation.lock('portrait') is called, the device is forced into that orientation. Running on an iPhone 6+, iOS 10.3.1

https://github.com/apache/cordova-plugin-screen-orientation/blob/master/RELEASENOTES.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants
You can’t perform that action at this time.