[英]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用户订阅了指定的频道
我无法发布图片,但是在Parse Core表中,它是单行,在“通道”列中带有[“ sdc_channel_6”,“ sdc_channel_5”,“ sdc_channel_2”,“ sdc_channel_3”,“ sdc_channel_4”],并且在更新时会更改用户的兴趣,所以我认为目前一切正常。
我正在使用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”表示“包含在”中,因此如果用户订阅了频道“ sdc_channel_9”和频道“ sdc_channel_8”,则将选择该用户。 可能是您应该尝试以下查询:
"where" : {"$or":[{"channels":"sdc_channel_99"},{"channels":"sdc_channel_88"}]}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.