2014-11-08 67 views
6

我制作了一个使用Parse.com推送通知的应用程序。我有一个设置页面,您可以在其中启用/禁用推送通知。设置页面运行良好,它改变了使用的偏好,但推送通知不会停止。Parse.com推送通知问题。取消订阅不工作,仍然收到推送通知。(Android)

这里是我的代码中,我订阅/退订:

SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); 
      pushNotificationsPreference = sharedPrefs.getBoolean("PUSH_NOTIFICATION_PREFERENCE", true); 

      if (pushNotificationsPreference) { 
       ParsePush.subscribeInBackground("Android", new SaveCallback() { 
        @Override 
        public void done(ParseException e) { 
         if (e != null) { 
          Log.d("com.parse.push", "successfully subscribed to the broadcast channel."); 
         } else { 
          Log.e("com.parse.push", "failed to subscribe for push" + e); 
         } 
        } 
       }); 
      } else { 
       ParsePush.unsubscribeInBackground("Android", new SaveCallback() { 
        @Override 
        public void done(ParseException e) { 
         if (e != null) { 
          Log.d("com.parse.push", "successfully subscribed to the broadcast channel."); 
         } else { 
          Log.e("com.parse.push", "failed to unsubscribe for push" + e); 
         } 
        } 
       }); 

      } 

如果 “pushNotificationsPreference” 是假的,它调用方法 “ParsePush.unsubscribeInBackground(” 机器人 “新SaveCallback()”,但它赢得了“T订阅,我仍然接受他们。

我去Parse.com,我只在‘Android’的通道注册。

我失去了什么?

+0

done()是否成功退订(日志)?另外指出,你的IF条件反向设置。 IF(e == null)表示没有错误,反之亦然。另外,您的偏好很可能不存在,并且默认值为“true”。 – Aashir 2015-06-06 20:35:21

回答

1

只需添加

if (e == null) { 
    ParseInstallation.getCurrentInstallation().saveInBackground(); 
} 

ParsePush.unsubscribeInBackground(...)