Its it possible to change Push Notifications subscribed to channels for a different device than the device the API is called from ?
Please clarify your use-case step-by-step like this:
- Register device 1 to first channel
- Sent push notification to first channel
- Register device 2 to second channel …e.t.c
well… all Im trying to do is to make sure users accessing My App using same user ID from different devices they will actually have same subscriptions to Push Notifications Channels on all devices…
so as a logical steps, it goes like this
- Create User1
- Access User 1 from Device 1 (so in Users Table will link Device 1 to User 1)
- Subscribe to Channel 1 From Device 1 . (The Users Table will add the channel 1 as record of subscribed to channels)
-Access User 1 from Device 2 (so Users Table will link Device 2 to User 1 and also Inform Device Device 2 to subscribe with Channel 1 to be in Synch with Device 1 push Notifications channels)
- Subscribe to Channel 2 From Device 2 … (Here for making sure Device 1 and Device 2 are subscribing to same Channels I need to fire a request from Device 2 itself to Subscribe Device 1 to the updated list of Channels (Channel 1 & Channel 2) … this is where I have an issue …
I think that I’ve got your idea. I assume that under “subscriptions to push notification channels”
you mean “registration”.
There is no way to receive push notification without device registration, so when the same user logins from another device - you should create a new one. I can offer you the following way:
- Create column “userPushChannels”, where you’ll save list of channels separated by any delimeter, say, comma
- Login user
- Retrieve list of channels for this user
- Assuming that you’d like to register device to channel named “Channel_X”: check if “Channel_X” is in the list. If it’s not - add “Channel_X” to the list and update “Users” object
- Register device passing the list of channels
This way if the user has been previously registered to any channel - he’ll be registered to them. Otherwise, if he logins from the device he has already used - his old registration would be extended.
Also do not forget to remove channel from the list when user cancels registration, if you use this feature in your app.
I hope that it helps.
Thanks for the detailed solution above, most probably I will have to move this way but I just had one issue with this:
The above solution means that for any device to receive the most recent notification messages for the recent channeled subscribed to, these deices will have to login first … I wanted to avoid this as typically user will be asked to login not that frequently and we will just keep the flag (setStayLoggedIn:YES) … so as long as the user Token is valid, he will not be prompt to login in again
Well, then you just should chain that “check+register” logic with another event. Then it would look like this:
- <Application starts>
- Check if there is a valid user-token
- If it is - move to step 5
- If it’s not - show “login” view and login user
- Retrieve list of channels for current user
- … see algorithm from my post above
It’s a good practice to re-register device each time application starts - push-messaging providers can expire device registrations from time to time.
Yup its the best option I guess … many thanks for your help
The way I did something like this in my app is register a user under a channel in their name. So no matter how many devices the user uses, they’d all be under that channel. When I send a notification to that user I just send it to the channel, and all devices would get it