【问题标题】:Parse.com filtering Push Notification as "multi server"Parse.com 将推送通知过滤为“多服务器”
【发布时间】:2016-03-08 05:17:48
【问题描述】:

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

我尝试了两种解决方案,但都有一些问题都与以下事实有关:当我启动我的应用程序时,我不知道用户会选择哪个“服务器”。

想法 1 - 真正的多服务器

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

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

  7. 一切正常,直到我尝试在应用程序关闭(非活动且不在后台)时发送推送通知,当我有一个 NullPointerException 由于 Parse 的初始化尚未调用。

想法 2 - 模拟多服务器

  1. 我手动创建了一个Parse.com 服务器
  2. 所有表都有一个新列,例如(仅作为示例)uniqueIdServer
  3. 我在 Application 中初始化 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. 但我不知道如何仅针对某些uniqueId 过滤推送通知
  8. 我尝试使用频道而不是仅在该频道发送推送:

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

非常感谢,任何帮助将不胜感激。

【问题讨论】:

    标签: android parse-platform push-notification multiserver


    【解决方案1】:

    使用您的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
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      • 2023-03-16
      • 2016-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多