Hello guys!
I’m looking again for anyone who managed to get iOS web browser (Safari) to allow me to get device motion and orientation data on HTML5.
The iOS is requesting permissions to be given after user input and it doesn’t work by Defold’s input, but I managed to do so from javascript by adding and handling a button in HTML5 on top of the Defold’s canva that requests permissions after clicking onit.
I got a popup with information about requested permissions, I clicked agree, but I don’t see any icon(?)/information, whether motion data is being collected or not.
Event handling code (JS):
DeviceOrientationEvent.requestPermission().then(response => {
if (response === "granted") {
window.addEventListener('deviceorientation', function(event) {
_processGyroscopeData(event.alpha, event.beta, event.gamma);
});
console.log("DeviceOrientationEvent permission granted.");
} else {
console.error("DeviceOrientationEvent permission denied.");
}
And code passing it to C++:
EMSCRIPTEN_KEEPALIVE void processGyroscopeData(double alpha, double beta, double gamma) {
currentGyroData.x = alpha;
currentGyroData.y = beta;
currentGyroData.z = gamma;
}
And then to Lua:
static int GetGyroscopeEuler(lua_State* L) {
// Gyroscope data is already in Euler angles (alpha, beta, gamma)
lua_pushnumber(L, currentGyroData.x); // Roll (alpha)
lua_pushnumber(L, currentGyroData.y); // Pitch (beta)
lua_pushnumber(L, currentGyroData.z); // Yaw (gamma)
return 3; // Returning Euler angles
}
And the data in deviceorientation event is 0… (alpha = 0, beta = 0, gamma = 0) (as initialized) all the time. How can I start data collection after getting permission form user?
Testing on iPhone Xs (iOS 16.6)