Manage Device
This section describes the different actions that could be performed on an indigitall device. The device model would have this structure:
device = {
deviceId: "string",
pushToken: "string",
browserPublicKey: "string",
browserPrivateKey: "string",
platform: "string",
version: "string",
productName: "string",
productVersion: "string",
browserName: "string",
browserVersion: "string",
osName: "string",
osVersion: "string",
deviceType: "string",
enabled: "boolean",
externalCode: "string"
};
Check device information and status
You can use the deviceGet method to get the information that the SDK has recorded regarding the device.
You must instantiate a DeviceCallback object and pass it as the second parameter of the deviceGet method. This callback will receive as a parameter the device object that contains all the information associated with the device.
indigitall.deviceGet((device) => {
// success function
console.log(device);
},() => {
// error function
});
Enable/disable device
You can choose to disable the device to block the receipt of notifications. It is a very useful method to:
- Implement a preferences screen so that the user can enable / disable the receipt of notifications.
- Avoid receiving notifications if the user has not logged in, or has not accepted the terms of use, etc.
- Manage the Robinson List.
To do this, you have the deviceEnable and deviceDisable methods.
You must instantiate a _Device Callback object and pass it as the second parameter. This callback will receive as a parameter the device object that contains all the information associated with the device.
indigitall.deviceEnable((device) => {
// success function
console.log(device);
},() => {
// error function
});
indigitall.deviceDisable((device) => {
// success function
console.log(device);
},() => {
// error function
});
Example of device use
We are going to see the implementation to check the status of the device where the application is running. We will carry out the operations of: checking the status of the device, enabling the status of the device and disabling the device.
First of all we need to create a view in HTML. We will do it as follows:
<div id="notifications-manager">
<p>Notifications:</p>
<!-- Rounded switch -->
<label class="switch">
<input type="checkbox">
<span class="slider round"></span>
</label>
</div>
After this, we will add the styles for the view inside the CSS:
/* The switch - the box around the slider */
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
/* Hide default HTML checkbox */
.switch input {display:none;}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
And finally, we will define the events indicated above in the guide in Javascript with jQuery.
$(() => {
indigitall.deviceGet((device) => {
if (device && device.enabled === true) {
$('.switch input[type=checkbox]')[0].checked = true;
} else {
$('.switch input[type=checkbox]')[0].checked = false;
}
});
$('.switch span.slider').click(() => {
if ($('.switch input[type=checkbox]')[0].checked === true) {
indigitall.deviceDisable((device) => {
console.log ('device disabled');
})
} else {
indigitall.deviceEnable((device) => {
console.log ('device enabled');
})
}
});
});