apache / cordova-plugin-screen-orientation

Apache Cordova Screen Orientation Plugin
https://cordova.apache.org/
Apache License 2.0
219 stars 228 forks source link

iOS 16.4 and 16.5 stops at screen.orientation.lock() #119

Closed kapchew closed 1 year ago

kapchew commented 1 year ago

Issue Type

Description

When testing in iOS 16.4 and 16.5, code execution stops at screen.orientation.lock();

Environment, Platform, Device

MacBook Pro M1 + iPad

Version information

Cordova CLI 11 cordova-ios 6.3 cordova-plugin-screen-orientation 3.0.3

Checklist

deepakrout commented 1 year ago

Hi There, I am also facing same issue, particularly in iOS 16.4 and above devices. Below iOS 16.4, the plugin works fine. In iOS 16.4 XCode debug console prints error:

Native: tried calling Screen Orientation.lock, but the Screen Orientation plugin is not installed.

Essentially, the it is not calling the plugin method at all. Breakpoints doesn't hit.

Is there any update/solution for this?

If someone can at least point me why it would throw error plugin not installed, I can work on this issue to address this.

Thank you!

DeveloperHitesh commented 1 year ago

Facing similar issue while trying to open camera in application.

ERROR: Unhandled Promise rejection: plugin_not_installed ; Zone: ; Task: Promise.then ; Value: plugin_not_installed WARN: Native: tried calling ScreenOrientation.lock, but the ScreenOrientation plugin is not installed. WARN: Install the ScreenOrientation plugin: 'ionic cordova plugin add cordova-plugin-screen-orientation' ERROR: Unhandled Promise rejection: plugin_not_installed ; Zone: ; Task: Promise.then ; Value: plugin_not_installed WARN: Native: tried calling ScreenOrientation.lock, but the ScreenOrientation plugin is not installed. WARN: Install the ScreenOrientation plugin: 'ionic cordova plugin add cordova-plugin-screen-orientation' ERROR: Unhandled Promise rejection: plugin_not_installed ; Zone: ; Task: Promise.then ; Value: plugin_not_installed

This issue is occure after getting update of ios version 16.4 and 16.5, on lower version i'm able to access camera easily.

Below plugin used for

"cordova-ios": "^6.3.0", "@ionic-native/camera-preview": "^5.27.0", "cordova-plugin-camera-preview": "^0.12.3", "cordova-plugin-screen-orientation": "^3.0.2"

Reference link for similar issue : https://github.com/ionic-team/capacitor/issues/6459

Implemented this change on local but not working : https://github.com/apache/cordova-plugin-screen-orientation/commit/f8479d5c7bc938edf782bf4ebcedc0cfa8ceb7e8

Can you help me on this any pointers on same it will help full for me.

Thanks in advance.

richpixel commented 1 year ago

Hi- I'm also seeing this issue when building my app. Luckily upgrading to 16.5 on devices that already have the app installed does not cause them to fail. If I put the call to screen.orientation.lock() in a try/catch block I get the following exception:

TypeError: window.screen.orientation.lock is not a function. (In 'window.screen.orientation.lock(e)', 'window.screen.orientation.lock' is undefined)

I'm looking into a workaround.

richpixel commented 1 year ago

I've been tinkering a little and notice that changing

screenObject.lock = function (orientation) {

to

ScreenOrientation.prototype.lock = function (orientation) {

fixes the problem of the lock function being undefined. I'm not sure how iOS versions less than 16.4 will handle this, so more testing needed.

Make-It-Racing commented 1 year ago

ScreenOrientation.prototype.lock

Great find! Please let us know when you have news about previous versions, I will try to find an old iphone to test as well....

ragcsalo commented 1 year ago

Nope, unfortunately the workaround doesn't work on older iOS versions. So we have to do this: www/screenorientation.js, around line 98:

if (typeof ScreenOrientation != 'undefined') {
  addScreenOrientationApi(ScreenOrientation.prototype);
}
else {
  addScreenOrientationApi(screen.orientation);
}

This works for me on iOS 16.5 and also 15.7

DeveloperHitesh commented 1 year ago

Due to xcode version update from 14.2 to 14.3 we are facing this issue, Again we moved from 14.3 to 14.2 issue is resolved, don't know what is update in xcode version but after downgrade xcode version resolved my issue.

FreddieFred34 commented 1 year ago

Is there an update about this issue? Facing the same issue.

Is there maybe a work around to force the app to Landscape mode?

richpixel commented 1 year ago

Is there an update about this issue? Facing the same issue.

Is there maybe a work around to force the app to Landscape mode?

Look at the comment from ragcsalo, if you're able to edit that one js file, it solves the issue. I would consider this a workaround, but it's fine until the plugin author releases an update.

Make-It-Racing commented 1 year ago

I just forced orientation to landscape of the whole app in xcode, that worked for me

FreddieFred34 commented 1 year ago

Nope, unfortunately the workaround doesn't work on older iOS versions. So we have to do this: www/screenorientation.js, around line 98:

if (typeof ScreenOrientation != 'undefined') {
  addScreenOrientationApi(ScreenOrientation.prototype);
}
else {
  addScreenOrientationApi(screen.orientation);
}

This works for me on iOS 16.5 and also 15.7

Fantastic this did indeed do the trick! Important is that you edit the correct screenorientation.js file :-)

gauravpatil79 commented 1 year ago

any idea how long it will take for the updated version of plugin?

yanbodang commented 1 year ago

Hi guys. There is a PR to fix it. How soon it can be merged? @maverickmishra @purplecabbage @alsorokin @janpio

erisu commented 1 year ago

Resolved in #116