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.