API: Detect Accelerometer Motion
Trigger actions based on a change in the tilt or angle of the iPad indicating motion of the device.
Requirements
- Integration of our JavaScript API into your webpage
- Sample code to run within the app and download for integration into your own project is available here.
- Best practices for working with the JavaScript API are available here.
- App Settings
- Content > JavaScript API > Access JavaScript API = By Import
- Device Access > Accelerometer Motion > Motion Detection Reset Period - must be configured, will affect the length of the motion session
Triggers via API Functions
Start Listening for Accelerometer Motion
This function triggers the app to start listening for changes in one of three possible tilts (roll, yaw, pitch) of the tablet.
Format | kp_AccelerometerAPI_startListenToEvents(callback); |
Parameters |
|
Callback format | callback(isListening, previouslyListening); |
Callback return values |
|
Stop Listening for Accelerometer Motion
This function triggers the app to stop listening for changes in one of three possible tilts (roll, yaw, pitch) of the tablet.
Format | kp_AccelerometerAPI_stopListenToEvents(callback); |
Parameters |
|
Callback format | callback(isListening, previouslyListening); |
Callback return values |
|
Check Current State
This function checks whether the app is currently listening for motion and whether a motion detection session is currently active.
Format | kp_AccelerometerAPI_getState(callback); |
Parameters |
|
Callback format | callback(isListening, sessionInProgress, secondsToSessionReset); |
Callback return values |
|
Notifications via API Callbacks
New Motion Detected
Triggers when new motion is detected. A motion detection session is started and will end if no continued motion is detected.
Format | kp_AccelerometerAPI_didDetectStartMotion(); |
Continued Motion Detection
Triggers when a motion detection session is currently in progress and motion is detected.
Format | kp_AccelerometerAPI_didDetectContinueMotion(); |
Motion Stopped
Triggers when a motion detection session is active and motion is not detected for the period defined by the Motion Detection Reset Period setting.
Format | kp_AccelerometerAPI_didDetectStopMotion(); |
Sample Code
- This sample code relies on the JavaScript APIs built into Kiosk Pro and will not run successfully in other browsers or within our in-app help interface.
- To run sample code, set the app's homepage to kioskgroup.com/accelerometer-api
- To download a .zip of sample code, click here.
Change Log
- Added in version 10.1