Parse.com过滤推送通知为“多服务器”

时间:2015-12-03 14:29:55

标签: android parse-platform push-notification multiserver

首先,我为我糟糕的英语道歉。我刚接近Parse.com,我正在开发一个“多服务器”应用程序,允许我发送由“服务器”过滤的通知。

我尝试了两种解决方案,但都有一些问题都与我开始使用应用程序时不知道用户会选择哪种“服务器”这一事实有关。

创意1 - 真正的多服务器

  1. 我手动创建n Parse.com个服务器,彼此完全分开
  2. 我将所有服务器密钥存储在[Name, AppID, clientKey]
  3. 等对象中
  4. 我的应用程序列出了名称属性
  5. 用户选择他的服务器
  6. 我开始新的Activity onCreate()我将Parse初始化为:

    String appID = getAppID();
    String cKey = getKey();
    Parse.initialize(this, appID, cKey);
    ParseInstallation.getCurrentInstallation().saveInBackground();
    
  7. (如果他想更改服务器我只需清理我的App数据并使用新密钥重新初始化Parse)

  8. 当我因为初始化Parse尚未调用NullPointerException而关闭应用程序(不活动且不在后台)时尝试发送推送通知,一切正常。
  9. 创意2 - 模拟多服务器

    1. 我手动创建一个Parse.com服务器
    2. 所有表都有一个新的列(就像示例)uniqueIdServer
    3. 我在应用程序中初始化Parse,如:

      public class MyApplication extends Application {
      @Override
      public void onCreate() {
          Parse.initialize(this, "ThisTimeIHaveJustOneAppIDIt'sEasy", "SameHere");
          ParseInstallation.getCurrentInstallation().saveInBackground();
          super.onCreate();
      }}
      
    4. 我显示旧列表,但这次只是[name,uniqueID]

    5. 用户选择他的“服务器”
    6. 现在我可以使用我的新专栏轻松过滤我的数据,当我的应用程序关闭时我没有问题,因为Parse将通过他自己的
    7. 调用他的初始化程序
    8. 但我不知道如何针对某些uniqueId
    9. 过滤推送通知
    10. 我尝试使用频道,而不是仅在该频道发送Push:

          List<String> channels = new ArrayList<>();
      channels.add(getUniqueID());
      ParseInstallation install = ParseInstallation.getCurrentInstallation();
      install.put("channels", channels);
      install.saveEventually();
      
    11. 但总是一样,我不知道“应用程序时间”我的用户会选择什么,所以我的getUniqueID()将绑定"null"或类似,更糟糕的是我不知道如何我可以更改频道(atm我只能在我卸载我的应用程序时)

    12. 真的非常感谢,任何帮助都会非常感激。

1 个答案:

答案 0 :(得分:0)

使用 idea 2 ,可以为安装提供自定义属性,并与任何其他对象一样查询。此外,可以使用安装查询进行推送。请参阅"advanced targeting" in the docs

最低限度,您可以这样说:

var query = new Parse.Query(Parse.Installation);
query.equalTo('uniqueIdServer', 'serverId123');

var data = { alert: "Ciao users of serverId123!" }

Parse.Push.send({ where: query, data: data }).then(function() {
    // this code runs after the push has been sent to APN
}, function(error) {
    // this code runs in case of an error
});