Page tree
Skip to end of metadata
Go to start of metadata

This guide explains how to use Global Events in a project.

Application Events

Application events are available since the very beginning of the Smartface as a mean for application components to exchange information. These events should be written in "app.js" file. The most well known usage of application events are given below:

NAMEDESCRIPTION
onApplicationCallReceived
Triggered when application is called by another application. The calling application may send data to this application during calling. This data format should be JSON parsable. For iOS, this method is equal to application handleOpenURL method. For Android, this method is triggered if an activity is called by another activity.
onDeviceShaked
Triggered when device is shaked.
onExit
Triggered before exiting application.
onMaximize
Triggered after application is maximized by long touched home button.
onMinimize
Triggered after application is minimized by long touched home button.
onReceivedNotification
This event is triggered in two cases. One of them is application is active and running; recieved a push notification or local notification. Second is app is not active, recieved a push notification. This event is fired after activating (maximize) the app usig the notification.
onSMSReceived
Triggered after an SMS is recieved.
onStart
Runs functions on application start after completing processing of Splash Page, other loading of Smartface Project objects and parsing of i18n/i18.js and app.js.
Application.onMinimize(e) = function Global_Events_OnMinimize(e){
    lastMinimizeTimeStamp = new Date(); // When you send your application to the background, this function will be triggered.
}

Application.onDeviceShaked(e) = function Global_Events_OnDeviceShaked(e){
    var newPIN = generatePIN();
    alert("Your new PIN = " + newPIN);
}

Application.onStart(e) = function Application_OnStart(e){
    alert("isUpdate : "+ e.isUpdate + "isFirstStart : " + e.isFirstStart + "oldVersion : " + e.oldVersion + "newVersion : " + e.newVersion);
}
 
function generatePIN() {
    var generatedPIN = Math.floor((Math.random() * 10000) + 1);
    return generatedPIN;

Device Events

Device events are available based on device hardware.

NAMEDESCRIPTION
onAccelerate
Creates action(s) that are run when Accelerometer detects a change. It returns e.x , e.y and e.z parameters where x, y and z stand for the coordinates.
onConnectionTypeChanged
Creates action(s) that are run when the type of the network connection is changed.
onLocationChanged
Creates action(s) that are run when location is changed. It returns e.lat and e.lng values for latitude and longitude.
var varAccX = 0;
var varAccY = 0;
var varAccZ = 0;
Device.onAccelerate(e) = function Global_Events_OnAccelerate(e) {
	varAccX = e.x;
	varAccY = e.y;
	varAccZ = e.z;
}
Device.onConnectionTypeChanged(e) = function Global_Events_OnConnectionTypeChanged(e) {
	alert("your connection type is : " + Device.connectionType);
}
var myLat = null;
var myLng = null;
Device.onLocationChanged(e) = function Global_Events_OnLocationChanged(e) {
	myLat = e.lat;
	myLng = e.lng;
}