Support Topics Documentation Slack YouTube Blog

Backendless Push Notification with React Native


(Alan Oakden) #1

Hi

I am keen to use backendless for app push notifications.

I currently have an expo react native app working with local notifications.

I am trying to figure out how to get backlendless to work with expo push notifications https://docs.expo.io/versions/latest/guides/push-notifications but there’s currently only backendless documentation on how to integrate with standard Java Android apps or swift / objective C apps on ios .

Has anyone done similar to what i am trying to achieve, or provide a bit of guidance?

I am unkeen on detaching from expo for this, as i feel it is unnecessary.


(Sergey Kukurudzyak) #2

we have no integration with expo push, but you can use backednless to send push notification.
to do this you have to:

  1. setup push notifications http://backendless.com/docs/js/doc.html#push_push_notification_setup_androi

  2. register device. To do this just store the following object to Data service to the DeviceRegistration table:

{
"deviceId":"some unique id that identify your device, you can generate it by your self",
"tokenDevice": "use this method to get it https://docs.expo.io/versions/v29.0.0/sdk/notifications#exponotificationsgetdevicepushtokenasyncconfig",
"operatingSystemName":"ANDROID or IOS",
"channelName":"optional filed, by default used 'default' channel"
}```
http://backendless.com/docs/js/doc.html#dynanchor4

3. then use backendless API to send push notification: http://backendless.com/docs/js/doc.html#dynanchor19

(Alan Oakden) #3

Thanks Sergey.

So, the expo documentation says : Note: Most people do not need to use this. It is easier to use getExpoPushTokenAsync unless you have a specific reason to need the actual device tokens.

So this means for backendless i MUST use the alternative method they’ve provided?

Can i not just POST:

  return fetch(PUSH_ENDPOINT, {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      token: {
        value: token,
      },
      user: {
        username: 'Brent',
      },
    }),
  });

And then use getExpoPushTokenAsync ?

I MUST use device IDs?


(Sergey Kukurudzyak) #4

yes, because I am not sure what kind of token returns with getExpoPushTokenAsync and getDevicePushTokenAsync should return native android or ios token which will be used to send messages to gcm or apns

if you use backednless api you do not need getExpoPushTokenAsync, you need it only if you would like to send messages with EXPO notification sdk

please clarify your question


(Alan Oakden) #5

Hi Sergey

Just to say, thank you for the help.

However, at the moment this isn’t suitable really.

The current need to use getDevicePushTokenAsync means that i have to build the standalone app each time to test with, which i can’t do efficiently. So i am having to progress this just following the expo guidance and working around it where possible - using a lot of logic within the app rather than the backend.

FYI the expo token is in this sort of format… ExponentPushToken[zzjgmSH_RfNFuj5RiiwY_G]

It’d be excellent if backendless had a way to do business logic which in turn triggers the required HTTP Post to https://exp.host/--/api/v2/push/send

I’ll need to see if i can figure doing custom business logic from backendless with this https://github.com/Alymosul/exponent-server-sdk-php