cordova-plugin-screen-orientation icon indicating copy to clipboard operation
cordova-plugin-screen-orientation copied to clipboard

iOS 16 may not respect a request to change orientation

Open msmtamburro opened this issue 3 years ago • 13 comments

Bug Report

Problem

Getting this issue on our radar early:

https://developer.apple.com/forums/thread/707735?answerId=721941022#721941022

What is expected to happen?

This approach used to work, but may not on iOS 16: [[UIDevice currentDevice] setValue:@(orientation) forKey:@"orientation"]

We may need to switch to: https://developer.apple.com/documentation/uikit/uiwindowscene/3975944-requestgeometryupdate/ (which would require building from XCode 14)

What does actually happen?

Information

Command or Code

Environment, Platform, Device

Version information

iOS 16 beta 4

Checklist

  • [ ] I searched for existing GitHub issues
  • [ ] I updated all Cordova tooling to most recent version
  • [ ] I included all the necessary information above

msmtamburro avatar Aug 04 '22 15:08 msmtamburro

Specific guidance: https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-16-release-notes

[UIViewController shouldAutorotate] has been deprecated is no longer supported. [UIViewController attemptRotationToDeviceOrientation] has been deprecated and replaced with [UIViewController setNeedsUpdateOfSupportedInterfaceOrientations].

Workaround: Apps relying on shouldAutorotate should reflect their preferences using the view controllers supportedInterfaceOrientations. If the supported orientations change, use `-[UIViewController setNeedsUpdateOfSupportedInterface

msmtamburro avatar Aug 11 '22 17:08 msmtamburro

Replacing line 78 with something like this might work (untested):

                if (@available(iOS 16.0, *)) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_15_5 // Xcode 14 and iOS 16, or greater
                    [self.viewController setNeedsUpdateOfSupportedInterfaceOrientations];
#endif
                } else {
                    [UINavigationController attemptRotationToDeviceOrientation];
                }

msmtamburro avatar Aug 11 '22 19:08 msmtamburro

Hello there!

i've tried replacing

[UINavigationController attemptRotationToDeviceOrientation]

with your code. Unfortunately when i force the orientationChange, it doesn't trigger. Meanwhile i cannot find any indication or clear example to use requestGeometryUpdate

tookiez avatar Sep 15 '22 13:09 tookiez

Upvoting that suggested change did not work for us either.

tory37 avatar Sep 16 '22 15:09 tory37

Apologies that I still haven't had time to play with this. For diagnostics: When you're trying to use setNeedsUpdateOfSupportedInterfaceOrientations from Xcode 14 RC on iOS 16, does your list of supported orientations only include the desired orientation?

msmtamburro avatar Sep 16 '22 16:09 msmtamburro

Hi, the fix is working, but you have to replace line 83 [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; with your code

Robertndrei avatar Sep 18 '22 09:09 Robertndrei

@Robertndrei ok, i've replaced every

[UIDevice currentDevice] setValue:value forKey:@"orientation"]

and

[UINavigationController attemptRotationToDeviceOrientation]

with

  if (@available(iOS 16.0, *)) {
      #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_15_5 // Xcode 14 and iOS 16, or greater
          [self.viewController setNeedsUpdateOfSupportedInterfaceOrientations];
      #endif
  } else {
      [UINavigationController attemptRotationToDeviceOrientation];
  } 

and now seems work correctly

tookiez avatar Sep 20 '22 15:09 tookiez

@tookiez's fix (replacing lines 78 and 83 with the suggestion from above) worked for me too. How can we help get this fix released?

chrisvasz avatar Sep 20 '22 19:09 chrisvasz

Actually only line 83 is necessary to be replaced

Robertndrei avatar Sep 20 '22 19:09 Robertndrei

Thanks for tracing this down, everyone!

I added a PR, but since the last update on this library was 2019, I have a feeling no PR will be merged in the near future: https://github.com/apache/cordova-plugin-screen-orientation/pull/102

"Band-aid" Repo

In the meantime, I created a repo with the fix: https://github.com/521dimensions/cordova-plugin-screen-orientation

You can use it with:

cordova plugin add git+ssh://[email protected]:521dimensions/cordova-plugin-screen-orientation.git

Hope this helps someone else!

jaydrogers avatar Sep 21 '22 20:09 jaydrogers

@jaydrogers i tested your fork on a Simulator with a iPhone X on iOS 12.4 Compiled on XCode 14. Add the moment screen orientation does not lock in any directions

jansgescheit avatar Sep 22 '22 07:09 jansgescheit

Strange!

If you find issues, chime in on this PR. Looks like a contributor is looking at it now: https://github.com/apache/cordova-plugin-screen-orientation/pull/102

jaydrogers avatar Sep 22 '22 14:09 jaydrogers

if use xcode 13,the following is better:

if (@available(iOS 16.0, *)) {
    #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_15_5
        SEL supportedInterfaceSelector = NSSelectorFromString(@"setNeedsUpdateOfSupportedInterfaceOrientations");
        [self.viewController performSelector:supportedInterfaceSelector];
    #endif
} else {
    [UINavigationController attemptRotationToDeviceOrientation];
}

laughsky avatar Oct 19 '22 10:10 laughsky