Skip to main content

iRidi API. Push notifications

Methods for sending push notifications to iOS and Android devices

Methods​

IR.SendPush​

Important

For iRidi Server only!

Send a push notification to a group of control panels

Syntax

IR.SendPush(title, js_data, group_id, [status_callback], [this_ptr], [sound_type]);

InputValueDescription
title"text of notify"type: string
notification text
js_data"data"type: string
data to pass to scripts in the client application receiving the push notification, JSON
group_id1type: number
ID of the Device group that will receive the notification. Configure groups in your account on the website, on the object's "Users and Panels" tab
status_callbackstatustype: function
push status handler function. The function receives an object containing the code and text description of the push notification delivery result
this_ptrthistype: this
context pointer, available in status_callback as this
sound_type0type: number
type of sound played when the device receives a push notification. 0 - short sound (default), 1 - long sound
Output
-

Example

// simple Push (send a text)
IR.SendPush("Hello World!", "Data", 1);
// advanced Push (with data to JS and status processing)
function status (object) {
IR.Log('Status of Push: ' + object.Error + ' - ' + object.ErrorDescription);
}
IR.SendPush("Hello World!", "data for JS", 1, status, this, 0);
Tip
  • the amount of text and data that can be sent in a push notification is limited and depends on the recipient device (2 KB for iOS, 4 KB for Android). If the allowed data size is exceeded, the method returns a delivery error
  • the characters & and # are not supported in message text or script data

Device groups​

For a control panel to receive a notification, it must be assigned to a group. A group is created on the website, on the "Users and Panels" tab in the cloud object's settings. A group is assigned to a "user+project" combination. Thus, each project belonging to one user can be assigned to different groups and receive different notifications.

AttachPushGroup.png

  1. Assign a group to a user and project. The group will automatically be assigned to any control panel on which the user signs in and downloads this project
  2. Assign a group to a control panel by HWID. You can remove or add groups for individual panels

CreateOrEditPushGroup.png

  1. Create a new group (you will use its Group ID to send push notifications)
  2. Groups to which the control panel (user and project) belongs
  3. Groups to which the control panel does not belong

Push status handler function​

Important

For iRidi Server only!

Runs whenever a push notification is sent and receives the delivery result: success or error.

function status (object)
{
IR.Log("Status of Push (Code): " + object.Error);
IR.Log("Status of Push (Text): " + object.ErrorDescription);
}
IR.SendPush("Hello World!", "Data", 1, status, this, 0);
  • object.Error - event code: the result of sending the push notification. Event codes:
    • 0 (Success) - successfully sent
    • 1-10 (Error) - error code
  • object.ErrorDescription - text description of the event

Events​

IR.EVENT_RECEIVE_PUSH_NOTIFY​

Important

For i3 pro only!

handler for data received with a push notification. It receives the notification text, data intended for JS, and the ID of the group for which the notification is intended.

Syntax

IR.AddListener(IR.EVENT_RECEIVE_PUSH_NOTIFY, 0, function (text, data, group) {}, [pointer]);

InputValueDescription
functionfunction() {}type: function
anonymous function or function reference
pointer-type: object
pointer to the object serving as the function context (optional)
Output
-

Example

IR.AddListener(IR.EVENT_RECEIVE_PUSH_NOTIFY, 0, function(text, data, group)
{
IR.Log("EVENT_RECEIVE_PUSH_NOTIFY:" + text + " data:" + data + " group:" + group);
if(data == "do the action")
{
IR.Log("Ok I do");
}
if(data.indexOf("{") == 0)
{
var obj = JSON.Parse(data);
if(typeof(obj) != "undefined")
{
IR.Log("Json:OK");
IR.Log(JSON.Stringify(obj));
}
}
});