Sendbird、cordova 推送通知功能

Sendbird, cordova push notification functionality

我正在使用 Sendbird and cordova, however they seem to offer an api for push notifications for all platforms except from Javascript. They have push notifications for Android, ios,Unity and .Net + Xamarin. 构建一个聊天应用程序。因为我是新手,所以我不确定 JS api 是否不完整,或者他们有不实施它的设计决策。

有人可以帮助我获取 Sendbird 和 Cordova 的推送通知吗,我想 FCM 是必需的。

我找到了一个零碎的解决方案。

您将需要使用 platfrom API 并安装以下两个命令。

  1. cordova 插件添加 phonegap-plugin-push --variable SENDER_ID="xxxxxxxx" --save
  2. cordova 插件添加 cordova-plugin-fcm

在您的项目中执行上述操作之前,您需要执行 Android and/or 1,2 and 3 for iOs.

的步骤 1 和 2

一旦全部完成,您应该将以下两个文件放在项目的根目录中,这样 "www" 就层次结构而言与文件同级。

  1. google-services.json
  2. GoogleService-Info.plist

一旦完成,请从 phone-gap-push 开始执行此步骤。理想情况下,您只需要以下代码片段即可注册令牌。

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    
});

注意事项 sendbird 仅在您离线时发送推送通知。推送通知的 iOs 或 Android 文档很好地突出了这些免责声明。

By setting up push notification service to an app, your app users can receive messages even when they are offline. Typically, you might want users to receive push notifications after their app goes into the background. SendBird SDK automatically detects if your app enters the background and updates the user's connection status to Disconnected. Therefore, in normal cases, you do not have to call disconnect explicitly.

您已经在 Sendbird 上实现了 corodva/phonegap/javascript 推送通知。

不,我不能告诉你为什么 Sendbird 没有类似的文档!如果有人有更好更有效的方法,我洗耳恭听。

Sendbird 现在在 registering/unregistering 设备的 JS SDK 中公开方法。

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

但是,我以这种方式注册的令牌显示在 sendbird 的仪表板上,但我没有收到通知。我会更新 when/if sendbird 的支持会回复我。