Hello everyone.
I just did a push notification system that works.
Now I want when a notification is sent to a new news reported on the application, as long as the user has not seen the new article that it is displayed as "unread".
Should we keep a file. JSON that the article is "unread" or what is the right way? Thanks.
My code for notification:
/////////// // Modules requiring var isAndroid = false; if (Ti.Platform.name == 'android') { isAndroid = true; var CloudPush = require('ti.cloudpush'); } var Cloud = require("ti.cloud"); var deviceToken = null; // Token reception if (isAndroid) { CloudPush.retrieveDeviceToken({ success: deviceTokenSuccess, error: deviceTokenError }); } else { Titanium.Network.registerForPushNotifications({ types: [ Titanium.Network.NOTIFICATION_TYPE_BADGE, Titanium.Network.NOTIFICATION_TYPE_ALERT, Titanium.Network.NOTIFICATION_TYPE_SOUND ], success:deviceTokenSuccess, error:deviceTokenError, callback:function(e){ // called when a push notification is received (on ios) notificationReceived(e); } }); } function deviceTokenSuccess(e) { deviceToken = e.deviceToken; loginCloud(); } function deviceTokenError(e) { //alert('Error during token reception : ' + e.error); } // Login the user function loginCloud(){ Cloud.Users.login( { login: 'mylogin', password: 'mypassword' }, function (e) { if (e.success){ subscribe(); } else Ti.API.info('Error: ' +((e.error && e.message) || JSON.stringify(e))); }); } // Subscribe to channel function subscribe(){ Cloud.PushNotifications.subscribeToken( { device_token: deviceToken, channel: "newAlert", type: Ti.Platform.name == 'android' ? 'android' : 'ios' }, function (e) { if (e.success) Ti.API.info('Subscribed to a channel'); else Ti.API.info('Error:\n' + ((e.error && e.message) || JSON.stringify(e))); }); } // Notification reception if (isAndroid){ // Process incoming push notifications for android CloudPush.addEventListener('callback', function (evt) { notificationReceived(evt); }); } function notificationReceived(e) { alert(e.data); // Your code to execute when a notification is received } ///////////