【问题标题】:Sendbird, cordova push notification functionalitySendbird、cordova 推送通知功能
【发布时间】:2018-06-16 13:51:50
【问题描述】:

我正在使用Sendbird 和cordova 构建一个聊天应用程序,但是它们似乎为除Javascript 之外的所有平台提供了推送通知的API。他们有AndroidiosUnity.Net + Xamarin. 的推送通知。因为我是新手,所以我不确定 JS api 是否不完整,或者他们有不实施它的设计决定。

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

【问题讨论】:

    标签: javascript cordova push-notification chat sendbird


    【解决方案1】:

    我找到了一个草率的解决方案。

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

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

    在您的项目中进行上述操作之前,您需要按照Android 的步骤 1 和 2 和/或 iOs 的步骤 1,2 和 3。

    完成后,您应该将以下两个文件放在项目的根目录中,这样“www”就层次结构而言是文件的兄弟。

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

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

    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 仅在您离线时发送推送通知。推送通知的 iO 或 Android 文档都很好地突出了这些免责声明。

    通过为应用设置推送通知服务,您的应用用户即使在离线时也可以接收消息。通常,您可能希望用户在他们的应用程序进入后台后接收推送通知。 SendBird SDK 会自动检测您的应用是否进入后台,并将用户的连接状态更新为已断开连接。因此,在正常情况下,您不必显式调用 disconnect。

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

    不,我不能告诉你为什么 Sendbird 没有记录类似的文件!如果有人有更好更有效的方法,我会全力以赴。

    【讨论】:

      【解决方案2】:

      Sendbird 现在在 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 的仪表板上,但我没有收到通知。当 sendbird 的支持回复给我时,我会更新。

      【讨论】:

        猜你喜欢
        • 2019-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-23
        • 2015-03-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多