mpetroff / pannellum

Pannellum is a lightweight, free, and open source panorama viewer for the web.
https://pannellum.org/
MIT License
4.23k stars 721 forks source link

isOrientationSupported returning false on iPad Pro #1093

Closed rbsam176 closed 2 years ago

rbsam176 commented 2 years ago

I don't think this is so much an issue with Pannellum, but I wanted to raise this here incase you were able to provide a workaround. When I load up a panorama on a 12.9-inch iPad Pro the orientation button is missing from the viewer, and running isOrientationSupported in console returns false. If I tell Safari to 'Request mobile site' then it will work, but the default behaviour is for it to load the desktop site and then Pannellum isn't able to interact with the motion API's that Apple provides. Any idea how I can get the site to load as if it's a mobile device by default?

mpetroff commented 2 years ago

I don't have an iPad, so I don't know what Apple is doing differently there. All I know is that it works fine on an iPhone with the latest version of Safari (as long as you're using HTTPS).

jrothig commented 2 years ago

I have the same problem: On an iPhone, the button shows up, on an iPad Pro (9.7in) it does not. But what's interesting: With "orientationOnByDefault": true, the iPhone as well as the iPad react to the orientation, although the button does not show on the latter ...

... some additional testing lead to the result which the OP mentioned: when requesting the desktop site (default on Safari as well as on Firefox), the button does not show up, but requesting the mobile site (default on Opera), the button shows up. But still the same interesting detail: no matter whether the button is visible or not, in any case pannellum reacts to the orientation (with "orientationOnByDefault": true,) on all the tested browsers.

So, my question would be: Do you use different tests for the display of the button and for the reaction of pannellum to the signals of the orientation sensor? And if yes, my proposal would be to use the same criteria (the one used for the reaction) for both tests.

P.S.: All my tests were made on IOS 15.5 on the iPad as well as on the iPhone.

mpetroff commented 2 years ago

@jrothig You figured out the problem. The logic for displaying the button checks for mobi in the user agent string. I did not know that the iPad does not identify as a mobile device.

Unfortunately, I don't have any reasonable ideas for avoiding the user agent check, since checking for the presence of window.DeviceOrientationEvent isn't enough to see if a device actually has an inertia measurement unit. Pannellum used to check if a DeviceOrientationEvent returned non-zero values, but this had to be changed when iOS 13 starting requiring a permission prompt to access such events. Now, the button is displayed if window.DeviceOrientationEvent is defined, HTTPS is used, and mobi is in the user agent string.

Instead I just added a check for a Mac user agent and support for touch input, since Safari uses the same user agent on Macs and iPads. Could you please confirm that the fix works?

jrothig commented 2 years ago

I can confirm that with that bugfix, the button now is visible even when the iPad requests the Desktop website. And it works even with iOS 15.6 (which is on that iPad since few minutes). So thanks a lot for the fix as well as for the complete pannellum! It is really a nice piece of software ;-)