Hi Serhii,
Thanks for your concern in looking into our issue.
On page show event, we are invoking a method to update the user id and stage name (unique identifier of user) in the device collection tables. This is to identify the user who are all login to the same device and to send the respective device notification of the login users.
Please find below script to update user info from the device the user login.
var app = document.URL.indexOf( 'a href="http://" rel="nofollow"http:///a' ) === -1 && document.URL.indexOf( 'a href="https://" rel="nofollow"https:///a' ) === -1;
if(app)
{
updateuseridappery();
}
function updateuseridappery() {
var cuurentuserdevicetoken = localStorage.getItem('devicetoken_app');
var cuurentuserdeviceID = localStorage.getItem('deviceid_app');
Code: Select all
//alert(cuurentuserdevicetoken+"token");
if (localStorage.getItem('key')) {
var requestBody = {
"userid": localStorage.getItem('key'),
"stagename": "" + localStorage.getItem('stagename') + ""
};
} else {
requestBody = {
"userid": 0
};
}
var deviceids = cuurentuserdeviceID.search(';');
if (deviceids != -1) {
var deviceids = cuurentuserdeviceID.split(';');
var device = deviceids[0] + "%3B" + deviceids[1];
} else {
var device = cuurentuserdeviceID;
}
$.ajax({
url: "[url=https://api.appery.io/rest/push/reg/]https://api.appery.io/rest/push/reg/[/url]" + device + "",
headers: {
"X-Appery-App-Id": apperyAppID,
"Content-Type": "application/json"
},
data: JSON.stringify(requestBody),
type: 'PUT',
crossDomain: true,
dataType: 'json',
success: function(data2) {
// alert("successssfully device stored");
},
error: function(status, error) {
$.mobile.loading('hide');
//navigator.notification.alert("", null, 'Opps! There seems to be an error. Please try again later.');
},
});
}
For your information, we get the device token and device id from the local storage variables that has been set on Device ready event as below,
setTimeout(function() {
var deviceid= localStorage.getItem('pushNotificationDeviceID');
var devicetoken=localStorage.getItem('pushNotificationToken');
Code: Select all
if(devicetoken){
localStorage.setItem('devicetoken_app',devicetoken);
}
if(deviceid){
localStorage.setItem('deviceid_app',deviceid);
}
}, 1);
Let me know if you need any other details.
Looking forward to your response.
Thanks,
SK