Send Push Notification to specific user instead of device(How to idenifiy, which user is login, if more then one user using same device) in Ionic/Cordova

2:51 PM



When you sending push notification then there is a big problem appear that How to identify which user is currently login on the specific device, if more then one user using same device, because a application create same 'device token' for a device, it's not depend that who is login.


Each time when user login: You’ve to maintain a column in the user table, suppose the column name is ‘has_duplicate_id’ by default it’ll be ‘false’.
  • Send the ‘device_id’ on server with ‘user_id’.
  • Check that this ‘device_id’ is already used by some other ‘user_id’ or not.
    • If ‘Yes’(device_id already exist for some other user_id) then update the ‘has_duplicate_id’ column ’true’ for the ‘user_ids’ which has already this ‘device_id’ and for this ‘user_id’ mark ‘has_duplicate_id’ to ‘false’.
    • If ‘No’(device_id not exist in DB) then update this ‘device_id’ for particular ‘user_id’.
  • Check that this ‘device_id’ is already used by some other ‘user_id’ or not.
  • When you’ve to send the push notification on particular user_id then :
     => First you’ve to check ‘has_duplicate_id’
    • If it’s set as ‘false’ then send the push notification on this device_id.
    • If it’s set as ‘true’ then make a ‘push_notification_queue’ table and push the information(save the notification information in table) in this table, whenever any user login then first you’ve to check this table, if any entry exist for this user_id in ‘push_notification_queue’ table then send the push notification and remove the details from ‘push_notification_queue’ table.     

This is a chat application DB design :

You Might Also Like

2 comments