【问题标题】:Parse.com push notifications issue. unsubscribe not working, still receiving push notifications.(Android)Parse.com 推送通知问题。取消订阅不起作用,仍然收到推送通知。(Android)
【发布时间】:2015-06-28 01:12:55
【问题描述】:

我制作了一个使用 Parse.com 推送通知的应用程序。我有一个设置页面,您可以在其中启用/禁用推送通知。设置页面运行良好,它更改了使用的首选项,但推送通知不会停止。

这是我订阅/取消订阅的代码:

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(“Android”, new SaveCallback()”,但它不会订阅,我还在接收它们。

我去了 Parse.com,我只在“Android”频道注册。

我错过了什么吗?

【问题讨论】:

  • 是否取消订阅成功(在日志中)?还指出,您的 IF 条件设置相反。 IF (e == null) 表示没有错误,反之亦然。此外,您的偏好很可能不存在,默认值为“true”。

标签: android notifications parse-platform


【解决方案1】:

只需添加

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

进入done()ParsePush.unsubscribeInBackground(...)

【讨论】:

    猜你喜欢
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多