I’m trying to get gyro and accelero updates in CoronaCards on iOS. After adding the following code straight from the examples:
-- Called when a new gyroscope measurement has been received. local function onGyroscopeDataReceived( event ) -- Calculate approximate rotation traveled via deltaTime. -- Remember that rotation rate is in radians per second. local deltaRadians = event.yRotation \* event.deltaTime local deltaDegrees = deltaRadians \* (180 / math.pi) end -- Set up the above function to receive gyroscope events if the sensor exists. if system.hasEventSource( "gyroscope" ) then Runtime:addEventListener( "gyroscope", onGyroscopeDataReceived ) end
and running the app, I get the following exception:
-[AppDelegate setGyroUpdatesEnabled:]: unrecognized selector sent to instance ...
It appears Corona is trying to invoke this selector on my AppDelegate and expecting the containing iOS app to do something (?!). But I cannot find any documentation. I implemented the selector and it does get called with a BOOL argument of YES.
Next, I tried the accelerometer.
local function onAccelerate( event ) print( event.name, event.xGravity, event.yGravity ) end Runtime:addEventListener( "accelerometer", onAccelerate )
This does not call “setGyroUpdatesEnabled”, and the app keeps running, but I do not get any accelerometer updates.
So my question: how do I get gyro and accelero (and possible compass) working in CoronaCards on iOS? Note: the gyro worked on Android just fine.
This is a bug in CoronaCards. It works fine on Corona SDK and CoronaEnterprise, but we haven’t refactored things so CoronaCards is incorrectly assuming the use of the AppDelegate we have in Corona SDK/Enterprise.
We already have a bug filed internally, but I don’t have an ETA yet. In the mean time, you can hook into the iOS accel/gyroscope events and send those to Lua, as explained here:
This is a bug in CoronaCards. It works fine on Corona SDK and CoronaEnterprise, but we haven’t refactored things so CoronaCards is incorrectly assuming the use of the AppDelegate we have in Corona SDK/Enterprise.
We already have a bug filed internally, but I don’t have an ETA yet. In the mean time, you can hook into the iOS accel/gyroscope events and send those to Lua, as explained here: