iOS15: How to use rotationX, accelerationX


I’d like to write some webapps with my students, but the old code doesn’t work anymore, because of security reasons, I think. So found this video: and tried it, but it doesn’t work because of the following error near line 13 (" DeviceOrientationEvent.requestPermission().catch(() => { ") with “SyntaxError: invalid arrow-function arguments (parentheses around the arrow-function may help)”

This my code and a link to it

Any help and tipps would be great.

Thanks in advance,

let permissionGranted = false;
let cx, cy;

function setup() {
  createCanvas(windowWidth, windowHeight);
  cx = width/2;
  cy = height/2;
  if (typeOf(DeviceOrientationEvent) !== 'undfined' && typeOf(DeviceOrientationEvent.requestPermission) === 'function') {
  	DeviceOrientationEvent.requestPermission().catch(() => {
  		//permission dialog
  		let button = createButton("Click to allow sensors");"font-size","24px");;
  		throw error;
  	  .then() => {
  		permissionGranted = true;
  } else {
  	text("no IOS13+ device");

function requestAccess() {
		.then(response => {
			if (response == 'granted') {
				permissionGranted = true;	
			} else {
				permissionGranted = false;	

function draw() {
	if (!permissionGranted) return;

	const dx = constrain(rotationX,-3,3);
	const dy = constrain(rotationY,-3,3);
	cx += dx;
	cy += dy;
	ellipse (cx,cy,200,200);

You’re invoking method Promise::then() empty, w/o passing any callback parameters to it:

Instead your fat-arrow function gotta be inside Promise::then()'s parentheses:

      .then(() => permissionGranted = true)

There’s no builtin function called typeOf() in JS. Instead JS has a unary operator called typeof:

Also ‘undfined’ isn’t 1 of the 8 possible strings. Rather it’s ‘undefined’:
typeof DeviceOrientationEvent != 'undefined'

if (typeof DeviceOrientationEvent != 'undefined' && DeviceOrientationEvent.requestPermission) {

The code block above can be significantly shortened like this:

    .then(response => permissionGranted = response == 'granted')

Thank you! Looks great. I’ll give it a try.