Backendless Support
 
Answered

Push Notifications channels

Its it possible to change Push Notifications subscribed to channels for a different device than the device the API is called from ?

Leave a Comment

Comments (7)

photo
1

Hello!

Please clarify your use-case step-by-step like this:

1. Register device 1 to first channel

2. Sent push notification to first channel

3. Register device 2 to second channel ....e.t.c

Alex

photo
1

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 ..

photo
1

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:

1. Create column "userPushChannels", where you'll save list of channels separated by any delimeter, say, comma

2. Login user

3. Retrieve list of channels for this user

4. 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

5. 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.

Alex

photo
1

Hi Alex

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

photo
1

Well, then you just should chain that "check+register" logic with another event. Then it would look like this:

1. <Application starts>

2. Check if there is a valid user-token

3. If it is - move to step 5

4. If it's not - show "login" view and login user

5. Retrieve list of channels for current user

6. .... 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.

photo
1

Yup its the best option I guess .. many thanks for your help

photo
1

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