Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse.com push notifications not consistently working receiving "GCM -MISMATCH SENDER ID" error

Push notifications from parse.com is not consistently working. Randomly push notifications will fail, resulting in a GCM - MISMATCH SENDER ID" error. It is my understanding that programmatically we do not have to do anything with the GCM because parse.com sends the objectId to GCM. In either case, I have not been able to pinpoint any specific reason why this error occurs sometimes and other times it doesn't. Additionally, I am using Parse version, 1.10.2.

My Application class has the following

Parse.initialize(this, APPLICATION_ID_DEBUG, CLIENT_KEY_DEBUG);
            Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
ParsePush.subscribeInBackground(Constants.CHANNEL, new SaveCallback() {
            @Override
            public void done(ParseException e) {
                if (Utils.checkIfNull(e)) {
                    // subscribed to channel
                } else {
                    // failed to subscribe to channel
                }
            }
        });

After the user logs into my app I attach a channel to them. The channel data I save is just the user's unique id I am getting from server.

        List<String> arryChannel = new ArrayList<>();
        arryChannel.add(uniqueUserId);

        final ParseInstallation parseInstallation = ParseInstallation.getCurrentInstallation();
        parseInstallation.put(Constants.CHANNEL, arryChannel);
        parseInstallation.saveInBackground(new SaveCallback() {
            @Override
            public void done(ParseException e) {
                if (Utils.checkIfNull(e)) {
                    // update channel with user's unique id
                } else {
                    // failed to update channel with user unique id
                }
            }
        });

Finally, when the user logs out I unsubscribe them from their channel. I added unsubscribe to try and prevent any one device from receiving multiple push notifications because they have logged in as multiple users into the app and subscribed to multiple channels. The following is how my code looks when you log out.

                    ParsePush.unsubscribeInBackground(Constants.CHANNEL, new SaveCallback() {
                        @Override
                        public void done(ParseException e) {
                            if (Utils.checkIfNull(e)) {
                                // successfully unsubscribed to channel

                                // save the updated (unsubscribed) parse installation
                                final ParseInstallation parseInstallation = ParseInstallation.getCurrentInstallation();
                                parseInstallation.put(Constants.CHANNEL, new ArrayList<String>());
                                parseInstallation.saveInBackground(new SaveCallback() {
                                    @Override
                                    public void done(ParseException e) {
                                        if (Utils.checkIfNull(e)) {
                                            // add whatever logs here to check for any issues with unsubscribing
                                        } else {
                                            // failed to update channel
                                        }
                                    }
                                });
                            } else {
                                Logger.e("PARSE", "failed to unsubscribed to channel: " + e.getMessage());
                            }
                        }
                    });

The result of this implementation is that when push notifications are not working, it will continue to fail for about 50-100 times. Then it will start working for about 150-200 times. Then it goes back to not working. It is not a work, not-work type back and forth. It is more of a fail, fail, fail multiples times and then success, success, success multiple times. Any help on what I am missing in my implementation is appreciated. Thanks in advance.

like image 755
portfoliobuilder Avatar asked Sep 26 '22 17:09

portfoliobuilder


1 Answers

I have finally figured out the answer to this question! The issue had nothing to do with my implementation. For anyone else experiencing this same conflict, please look for any other 3rd party services that also are using push notifications. For me, Mixpanel was the culprit. When I deleted mixpanel.initPushHandling() from my codebase, all started working. And this makes sense, because when you initialize push notifications for mixpanel, you pass in a value that is used for GCMSenderID. Parse push notifications work differently. With parse.com, you do not have to send a GCMSenderID, because parse will automatically send in an objectId to perform their push notifications. Between the two, this causes a GCM-MISMATCH-SENDER error.

So the solution is, remove any sort of services that may be conflicting with parse.com. And feel free to use my implementation, it is good. Cheers!

like image 70
portfoliobuilder Avatar answered Sep 30 '22 08:09

portfoliobuilder