Sendbird notification function, cordova

I am creating a chat application using Sendbird and cordova, however they seem to offer api for push notifications for all platforms except Javascript . They have push notifications for Android , ios , Unity, and .NET + Xamarin. . Since I am a newbie, I am not sure if the JS api is incomplete or it has design solutions that do not implement it.

Can someone help me to get push notifications for Sendbird and Cordova, I assume FCM will be required.

+5
source share
2 answers

I found a patchwork solution.

You will need to use the platfrom API and install the following two commands.

  • plug cordova add phonegap-plugin-push -variable SENDER_ID = "xxxxxxxx" --save
  • plug cordova add cordova-plugin-fcm

Before you start working on a project, you will need to follow steps 1 and 2 for Android and / or 1,2 and 3 for iOs .

Once everything is complete, you must place the following two files in the root directory of your project so that "www" is native to the files in terms of hierarchy.

  • Google-services.json
  • GoogleService-Info.plist

after compelete performs this step from phone-break-press . Ideally, you only need the following snippet to register a token.

const push = PushNotification.init({ android: { }, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' }, ios: { alert: "true", badge: "true", sound: "true" }, windows: {} }); push.on('registration', (data) => { // what you get back in your data variable will be two things // registrationId and registrationType // Use the returned values to make the platform api call to sendbird }); 

It is important to note that sendbird only sends push notifications when you are offline. Either iO or the Android documentation for push notifications emphasize these disclaimers very well.

By installing the push notification service in the application, users of your application can receive messages even offline. Typically, users can receive push notifications after their application goes into the background. The SendBird SDK automatically detects whether your application enters the background and updates the status of the user’s connection to the disconnected one. Therefore, in normal cases, you do not need to explicitly disconnect communications.

There you have an implementation of corodva / phonegap / javascript push notifications about Sendbird.

And no, I can’t tell you why Sendbird did not document this! If anyone has a more efficient way, I'm all ears.

+1
source

Sendbird now provides methods in the JS SDK for registering / unregistering devices.

 getPendingGCMToken(): string; getPendingAPNSToken(): string; registerGCMPushTokenForCurrentUser(gcmRegToken: string, callback?: pushSettingCallback): void; unregisterGCMPushTokenForCurrentUser(gcmRegToken: string, callback?: commonCallback): void; unregisterGCMPushTokenAllForCurrentUser(callback?: commonCallback): void; registerAPNSPushTokenForCurrentUser(apnsRegToken: string, callback?: pushSettingCallback): void; unregisterAPNSPushTokenForCurrentUser(apnsRegToken: string, callback?: commonCallback): void; unregisterAPNSPushTokenAllForCurrentUser(callback?: commonCallback): void; unregisterPushTokenAllForCurrentUser(callback?: commonCallback): void; // This removes both All APNS/GCM tokens 

However, I have tokens registered in this way that appear on the sendbird control panel, but I do not receive a notification. I will update when / if sendbird support comes back to me.

0
source

Source: https://habr.com/ru/post/1274551/


All Articles