The compass sample not working in latest IOS device

I’ve tried using the compass sample in the appstudio but it seems does not work in the latest IOS12, but it works fine in IOS11. Device. Anyone face the same problem. Any advice is much appreciated.

When you say “not working” what do you mean? The app doesn’t load? The app starts but doesn’t display the compass?

It looks like the window.ondeviceorientation event is now happening before the compass gets its bearings. Here’s the corrected code in JavaScript

pos="0";

window.ondeviceorientation = function(e) {
  Label1.text=e.webkitCompassHeading;
  if(Label1.text=="undefined") {
    Label1.text="Compass not supported on this device";
 } else {
    Label1.text="";
  }

  pos = e.webkitCompassHeading;
  imgCompass.style.webkitTransform="rotate("  +  pos  +  "deg)";
  imgCompass.style.webkitTransform="rotate(-"  +  pos  +  "deg)";
};

and in BASIC

pos="0"

Function window_ondeviceorientation(e)
  Label1.text=e.webkitCompassHeading
  If Label1.text="undefined" Then 
    Label1.text="Compass not supported on this device"
  Else  
    Label1.text=""
  End If
  
  pos = e.webkitCompassHeading
  imgCompass.style.webkitTransform="rotate(" & pos & "deg)"
  imgCompass.style.webkitTransform="rotate(-" & pos & "deg)"
End Function

Thanks for reply.
I’ve Run the source code you provided and deploy it to the demo account. The app can load, compass image appear, but image still does not move/response according to the movement of the iPhonex

As mentioned earlier compass sample/app loads and operating fine with iphone operating on earlier iOS11 and below, and not the current ios12.

It’s working fine here. Where are you deploying to? I’ll try your code here.

Hi George,
I deployed it to the demo account volt account. And also to my hosting website.

Hi George,
I’m sure the compass sample code will work as I’ve run it on 2 different iPhones with ios11 and ios12 respectively, one operating fine and the other, the compass image just freeze with the display message: “compass not supported on this device”.

Hope this helps…

Can you give me the url of your Volt deploy?

Hi George,
The url:
https://compass6-cares-busily.volt.live

Ps: I’m using iPhoneX on IOS12

Your app works fine here on my iPhone 8 with iOS 12.2.

Try clearing the cache on the device.

Hi George,

I’ve managed to find out the root cause. Somehow the motion and orientation access setting in Safari is disabled. I’ve enabled it and the compass function works now…

Sorry for the inconvenience caused. And many thanks for your advice and effort.

Regards,
Martin

Hi George,

Just to share with you that I’ve just test run on more iOS version with compass sample code onto godaddy shared webhosting(Linux)

iPhone 6 ios11 - compass image response to movement, work fine.

iPhone 6 ios12 - compass image response to movement, work fine.

iPhone 6 iOS 12.3.1 - compass image doesn’t response.

iPhone X iOS 12.3.1 - compass image doesn’t response.

When it deploys to demo account of volt.live, all compass sample code are working fine.

Just Curious

  • if there is any setup I need to aware.

  • it seems it is not so friendly with the latest IOS 12.3.1 on godaddy webserver.

Regards

Martin

That doesn’t make much sense to me. Could you share your GoDaddy link? Maybe I can see something.

Hi George,

I fully agree with you. That’s why I’m still snatching my head to find out the root cause.

The url as follows:

Compass


Compass

Show the current compass reading. (iOS)

Hope this helps. Thanks

Regards

Martin

When I run your app on Chrome and look at the console, I see this message:

[Deprecation] The deviceorientation event is deprecated on insecure origins and will be removed in M76, around July 2019. Event handlers can still be registered but are no longer invoked since M74, around April 2019. See Chrome Platform Status for more details.

Looks like you’ll need a signed GoDaddy account. Volt is fully signed, so it works there.

Hi George,

Thanks for the valuable findings.

Just curious that the compass sample is still working on earlier IOS version.

Nevertheless, it will be appropriate to have a signed account. Thanks again.

Regards
Martin

The browser community is implementing steadily better security as time goes on. Older devices use older versions of Safari, which are more tolerant of security issues.