Parse.com
,我正在开发一个“多服务器”应用程序,允许我发送由“服务器”过滤的通知。
我尝试了两种解决方案,但都有一些问题都与我开始使用应用程序时不知道用户会选择哪种“服务器”这一事实有关。
创意1 - 真正的多服务器
Parse.com
个服务器,彼此完全分开[Name, AppID, clientKey]
我开始新的Activity
onCreate()
我将Parse初始化为:
String appID = getAppID();
String cKey = getKey();
Parse.initialize(this, appID, cKey);
ParseInstallation.getCurrentInstallation().saveInBackground();
(如果他想更改服务器我只需清理我的App数据并使用新密钥重新初始化Parse)
NullPointerException
而关闭应用程序(不活动且不在后台)时尝试发送推送通知,一切正常。创意2 - 模拟多服务器
Parse.com
服务器uniqueIdServer
我在应用程序中初始化Parse,如:
public class MyApplication extends Application {
@Override
public void onCreate() {
Parse.initialize(this, "ThisTimeIHaveJustOneAppIDIt'sEasy", "SameHere");
ParseInstallation.getCurrentInstallation().saveInBackground();
super.onCreate();
}}
我显示旧列表,但这次只是[name,uniqueID]
uniqueId
我尝试使用频道,而不是仅在该频道发送Push:
List<String> channels = new ArrayList<>();
channels.add(getUniqueID());
ParseInstallation install = ParseInstallation.getCurrentInstallation();
install.put("channels", channels);
install.saveEventually();
但总是一样,我不知道“应用程序时间”我的用户会选择什么,所以我的getUniqueID()
将绑定"null"
或类似,更糟糕的是我不知道如何我可以更改频道(atm我只能在我卸载我的应用程序时)
真的非常感谢,任何帮助都会非常感激。
答案 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
});