Skip to content

User Guide: SDKs > VoltMX Iris SDK > Register

Invoking a Messaging Service

A developer should register with Google Cloud Messaging (GCM) for Android services to get the deviceToken that is used to register with Volt MX Foundry Messaging. Also a developer should fetch the deviceId and   userfriendlyId to create an instance of messaging service.

The following are the methods you can use for a messaging service.

Register

Register API registers to the engagement server.

Syntax

register = function(osType, deviceId, regID, UFID,successCallback, failureCallback, options)

Parameters

Name Type Description Required
osType String Type of operating system Yes
deviceID String Device ID of the device Yes
regID String Registration ID of the user Yes
UFID String User friendly ID configured in messaging service console Yes
successCallback Function Method invoked on success Yes
failureCallback Function Method invoked on failure Yes
options JSON Map for optional parameters Optional

Optional Keys

Key Type Description Required
authToken String Authorization token configured in messaging service console. Optional

Example

// Get an instance of SDK
var client = voltmx.sdk.getCurrentInstance();
var messagingSvc = client.getMessagingService();
var deviceId = voltmx.os.deviceInfo().deviceid;
var UFID = "user_friendly_id";
var osType = "iphone"; /*"androidgcm" for android, "iphone" for iphone, "ipad" for ipad, "ipod" for ipod*/
var options = {
    "authToken": "authorization_token"
}; //To get regID, use voltmx.push.register() method 
var regID = voltmx.push.register();
messagingSvc.register(osType, deviceId, regID, UFID, function(response) {
    voltmx.print("register with auth token success: " + JSON.stringify(response));
}, function(error) {
    voltmx.print("register with auth token failed: " + JSON.stringify(error));
}, options);

Register with Auth Token

The registerWithAuthToken API registers with an Auth Token for the messaging service.

Syntax

registerWithAuthToken = function(osType, deviceId, regID, UFID, authToken, successCallback, failureCallback)

Parameters

Name Type Description   Required
osType String Type of operating system Yes
deviceId String Device ID of the device Yes
regID String Registration ID of the user. Yes
UFID String User friendly id or reconciliation key which is configured in engagement console. Yes
authToken String Authorization token configured in engagement console Yes
successCallback Function Method invoked on success Yes
failureCallback Function Method invoked on failure Yes

Example

// Sample code to register with an Auth Token
// Get an instance of SDK
var client = voltmx.sdk.getCurrentInstance();
var messagingSvc = client.getMessagingService();
messagingSvc.registerWithAuthToken("osType", "deviceId", "regID", "UFID", "authToken", function(response) {
    voltmx.print("Subscription Success: " + JSON.stringify(response));
}, function(error) {
    voltmx.print("Subscription Failure: " + JSON.stringify(error));
});

Important: You must register to a messaging service at least once to use the following APIs.

Unregister

Unregister API unregisters with the engagement server.

Syntax

unregister = function(successCallback, failureCallback, options)

Parameters

Name Type Descroption Required
successCallback Function Method invoked on success Yes
failureCallback Function Method invoked on failure Yes
options JSON Map for optional parameters Optional

Optional Keys

Key Type Description Required
authToken String Authorization token configured in messaging service console. Optional

Example

// Get an instance of SDK
var client = voltmx.sdk.getCurrentInstance();
var messagingSvc = client.getMessagingService();
var options = {
    "authToken": "xyz"
};
messagingSvc.unregister(function(response) {
    voltmx.print("Unregistration Success: " + JSON.stringify(response));
}, function(error) {
    voltmx.print("Unregistration Failure: " + JSON.stringify(error));
}, options);

Unregister with Auth Token

The unregisterWithAuthToken API unregisters from the messaging service with the Auth Token.

Syntax

unregisterWithAuthToken = function(authToken, successCallback, failureCallback)

Parameters

Name Type Descroption Required
successCallback Function Method invoked on success Yes
failureCallback Function Method invoked on failure Yes
options JSON Map for optional parameters Optional

Optional Keys

Key Type Description Required
authToken String Authorization token configured in messaging service console. Optional

Example

// Get an instance of SDK
var client = voltmx.sdk.getCurrentInstance();
var messagingSvc = client.getMessagingService();
var authToken = "Authorization token configured in messaging service console";
messagingSvc.unregisterWithAuthToken(authToken, function(response) {
    voltmx.print("Unregistration Success: " + JSON.stringify(response));
}, function(error) {
    voltmx.print("Unregistration Failure: " + JSON.stringify(error));
});

Register geoBoundaries

The registerGeoBoundaries API registers geoboundaries to be monitored by the Engagement Service. The parameters of this API specify the radius and number of geoboundaries to monitor.

Important: When User registers for Geofence alert, some times there may be a delay in alerts, as per Google.
The Geofence service does