管理FCM设备组 [英] Managing FCM device groups

查看:290
本文介绍了管理FCM设备组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



AFAIK这些是更新的文档: href =https://firebase.google.com/docs/cloud-messaging/android/device-group#managing_device_groups =nofollow noreferrer> https://firebase.google.com/docs/cloud-messaging/ android / device-group#managing_device_groups



以下是我已经可以做的事情:


  • 使用一些设备令牌创建一个新的设备组
  • 将设备令牌添加到现有设备组


这就是我不知道该怎么做的,因为在文档里没有提到它:


  • 根据其 notification_key_name 查询设备组是否已经存在。解决方法1:if我试着用 notification_key_name
    创建一个已经存在的组,然后我得到一个错误告诉我这样,但似乎
    很像 hacky的方法。



    解决方法2:将信息存储在其他地方。

    找出哪些设备令牌( registration_id )属于一个设备组。
    $ b

    解决方法:像以前一样,将信息存储在其他地方。

  • 删除设备令牌 registration_id )。

    解决方法:无。


  • 删除设备组。



    解决方法:无。

  • b

    感谢!

    解决方案



    • 查询根据其 notification_key_name


    $是否已存在设备组b $ b

    您的第二个解决方法是要走的路。您应该将其存储在您的应用程序服务器中,与您同时在其中存储注册令牌的地方一样。






    • 找出哪些设备令牌( registration_id )属于设备组。


    与上述解决方法相同。您必须在App Server上管理这些详细信息。管理这些细节是开发者的责任。如果注册设备被删除,匹配操作,你也必须从你的应用程序服务器中删除它。








    • 从设备组中删除设备令牌( registration_id )。

    我不确定您在这里需要什么。 文档有关于从设备组中删除注册令牌的详细信息:
    $ b


    从设备组添加和删除设备



    要从现有组添加或删除设备,请发送POST请求,并将操作参数设置为添加删除,并提供添加或删除的注册标记。
    $ b注意
    :如果您从设备组中删除所有现有的注册令牌,FCM将删除设备组。
    $ b

    HTTP POST请求

    例如,设备注册ID 51到appUser-Chris,您可以发送此请求:

      {
    operation: add,
    notification_key_name:appUser-Chris,
    notification_key:APA91bGHXQBB ... 9QgnYOEURwm0I3lmyqzk2TXQ,
    registration_ids:[51]
    }

    回复格式

    成功添加或移除设备的请求会返回如下所示的notification_key:

      {
    notification_key:APA91bGHXQBB ... 9QgnYOEURwm0I3lmyqzk2TXQ
    }

    注意 notification_key_name 不需要添加/删除注册令牌,但包括它可以防止意外使用不正确的 notification_key








    • 删除设备组。


    从上述文档中的提示:


    $ b


    注意:如果从设备组中删除所有现有的注册令牌,则FCM将删除设备组。 b $ b


    I'm trying to figure out how to manage FCM device groups from an app server by using the REST API.

    AFAIK these are the updated docs: https://firebase.google.com/docs/cloud-messaging/android/device-group#managing_device_groups

    Here's what I can already do:

    • Create a new device group with some device tokens
    • Add device tokens to an existing device group

    And this is what I just can't figure out how to do since there's no mention of it in the docs:

    • Query whether a device group already exists, based on its notification_key_name.

      Workaround 1: if I try creating a group with a notification_key_name that already exists then I get an error telling me so, but that seems like a very hacky way to find out.

      Workaround 2: Store that information by myself somewhere else.

    • Finding out which device tokens (registration_id) belong to a device group.

      Workaround: as before, store that information by myself somewhere else.

    • Remove device tokens (registration_id) from a device group.

      Workaround: none.

    • Remove a device group.

      Workaround: none.

    Thanks!

    解决方案

    • Query whether a device group already exists, based on its notification_key_name.

    Your 2nd workaround is the way to go. You should store it in your App server, same where you also store the Registration Tokens.


    • Finding out which device tokens (registration_id) belong to a device group.

    Same as the workaround above. You have to manage these details on your App Server. It is the developer's responsibility to manage these details. Matching the actions if the registration device is removed, you'll have to remove it from your App Server as well.


    • Remove device tokens (registration_id) from a device group.

    I'm not sure what you need here. The documentation have details on removing registration tokens from the device group:

    Adding and removing devices from a device group

    To add or remove devices from an existing group, send a POST request with the operation parameter set to add or remove, and provide the registration tokens for addition or removal.

    Note: If you remove all existing registration tokens from a device group, FCM deletes the device group.

    HTTP POST request

    For example, to add a device with the registration ID 51 to appUser-Chris, you would send this request:

    {
       "operation": "add",
       "notification_key_name": "appUser-Chris",
       "notification_key": "APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ",
       "registration_ids": ["51"]
    }
    

    Response format

    A successful request to either add or remove a device returns a notification_key like the following:

    {
       "notification_key": "APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ"
    }
    

    Note: notification_key_name is not required for adding/removing registration tokens, but including it protects you against accidentally using the incorrect notification_key.


    • Remove a device group.

    From the note in the docs above:

    Note: If you remove all existing registration tokens from a device group, FCM deletes the device group.

    这篇关于管理FCM设备组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆