Parse.com 即使没有订阅频道也会收到推送通知
Parse.com Receiving push notifications even if not subscribed to channel
即使我没有订阅频道,我也会收到推送通知。
我的应用程序从远程 JSON 获取用户兴趣并订阅他到 Parse 中的频道。
我会尝试复制所有相关代码。
MyApplication.java
Parse.enableLocalDatastore(this);
Parse.initialize(this, ParseAppID, ParseClientKey);
ParseInstallation installation=ParseInstallation.getCurrentInstallation();
installation.put("UniqueId", android_id);
installation.saveInBackground();
MainActivity.java(在 AsyncTask onPostExecute 内)
JSONObject jObject = new JSONObject(result);
int error = jObject.getInt("Error");
ArrayList<String> channels = new ArrayList<String>();
if(error==0){
JSONArray intereses = jObject.getJSONArray("Interests");
Log.d("ChannelsTrack", "Error: 0");
for(int j=0; j < intereses.length(); j++) {
int interes = intereses.getInt(j);
String channel_name="sdc_channel_" + interes;
channels.add(channel_name);
Log.d("ChannelsTrack", channel_name);
ParsePush.subscribeInBackground( channel_name );
}
List<String> subscribedChannels = ParseInstallation.getCurrentInstallation().getList("channels");
for(int j=0; j < subscribedChannels.size(); j++) {
if(!channels.contains(subscribedChannels.get(j))){
ParsePush.unsubscribeInBackground( subscribedChannels.get(j) );
}
}
}else{
Log.d("ChannelsTrack", "Error: " + error);
}
这显然有效。我可以在控制台看到我的 Parse 用户订阅了指定频道
我不能 post 图片,但是在 Parse Core table 中它是单行 ["sdc_channel_6","sdc_channel_5","sdc_channel_2","sdc_channel_3","sdc_channel_4"] 在 "channels" 列中,当我更新用户兴趣时它会发生变化,所以我认为此时一切正常。
我正在使用 REST API 使用此 JSON
发送推送通知
{
"data": {
"action": "my.application.UPDATE_STATUS",
"t": "Text",
"d": "Text 2",
"f": "",
"u": "http://example.com"
},
"where": {
"channels": {
"$in": ["sdc_channel_99","sdc_channel_88"]
},
"deviceType": "android"
}
}
这就是问题所在。我收到了发送到 "sdc_channel_99" 和 "sdc_channel_88" 频道的推送通知,但我没有订阅它们(而且我从未订阅过它们)。
显然我遗漏了什么,有什么帮助吗?谢谢
我认为问题出在您的复合查询中:
"where": {
"channels": {
"$in": ["sdc_channel_99","sdc_channel_88"]
},
"$in" 表示 "Contained In" 因此如果用户订阅了频道 "sdc_channel_9" 和频道 "sdc_channel_8",该用户将被选中。
也许你应该试试这个查询:
"where" : {"$or":[{"channels":"sdc_channel_99"},{"channels":"sdc_channel_88"}]}
即使我没有订阅频道,我也会收到推送通知。
我的应用程序从远程 JSON 获取用户兴趣并订阅他到 Parse 中的频道。
我会尝试复制所有相关代码。
MyApplication.java
Parse.enableLocalDatastore(this);
Parse.initialize(this, ParseAppID, ParseClientKey);
ParseInstallation installation=ParseInstallation.getCurrentInstallation();
installation.put("UniqueId", android_id);
installation.saveInBackground();
MainActivity.java(在 AsyncTask onPostExecute 内)
JSONObject jObject = new JSONObject(result);
int error = jObject.getInt("Error");
ArrayList<String> channels = new ArrayList<String>();
if(error==0){
JSONArray intereses = jObject.getJSONArray("Interests");
Log.d("ChannelsTrack", "Error: 0");
for(int j=0; j < intereses.length(); j++) {
int interes = intereses.getInt(j);
String channel_name="sdc_channel_" + interes;
channels.add(channel_name);
Log.d("ChannelsTrack", channel_name);
ParsePush.subscribeInBackground( channel_name );
}
List<String> subscribedChannels = ParseInstallation.getCurrentInstallation().getList("channels");
for(int j=0; j < subscribedChannels.size(); j++) {
if(!channels.contains(subscribedChannels.get(j))){
ParsePush.unsubscribeInBackground( subscribedChannels.get(j) );
}
}
}else{
Log.d("ChannelsTrack", "Error: " + error);
}
这显然有效。我可以在控制台看到我的 Parse 用户订阅了指定频道
我不能 post 图片,但是在 Parse Core table 中它是单行 ["sdc_channel_6","sdc_channel_5","sdc_channel_2","sdc_channel_3","sdc_channel_4"] 在 "channels" 列中,当我更新用户兴趣时它会发生变化,所以我认为此时一切正常。
我正在使用 REST API 使用此 JSON
发送推送通知{
"data": {
"action": "my.application.UPDATE_STATUS",
"t": "Text",
"d": "Text 2",
"f": "",
"u": "http://example.com"
},
"where": {
"channels": {
"$in": ["sdc_channel_99","sdc_channel_88"]
},
"deviceType": "android"
}
}
这就是问题所在。我收到了发送到 "sdc_channel_99" 和 "sdc_channel_88" 频道的推送通知,但我没有订阅它们(而且我从未订阅过它们)。
显然我遗漏了什么,有什么帮助吗?谢谢
我认为问题出在您的复合查询中:
"where": {
"channels": {
"$in": ["sdc_channel_99","sdc_channel_88"]
},
"$in" 表示 "Contained In" 因此如果用户订阅了频道 "sdc_channel_9" 和频道 "sdc_channel_8",该用户将被选中。 也许你应该试试这个查询:
"where" : {"$or":[{"channels":"sdc_channel_99"},{"channels":"sdc_channel_88"}]}