Skip to content

Commit fc8e552

Browse files
sumeruchatEvan Greerevantk91
authored
Logic fix suggestion for Push Notifications (#859)
* [MOB-9446] Logic fix * [MOB-9446] Logic fix * [MOB-9446] Logic fix * [MOB-9446] Logic fix * [MOB-9446] Logic fix * adds register push path for system notifications * [MOB-9446] Logic fix --------- Co-authored-by: Evan Greer <[email protected]> Co-authored-by: Evan Takeo Kanaiaupuni Greer <[email protected]>
1 parent 4fcbe15 commit fc8e552

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

Diff for: iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java

+20-13
Original file line numberDiff line numberDiff line change
@@ -390,26 +390,33 @@ public void onSwitchToBackground() {}
390390
};
391391

392392
private void onForeground() {
393-
boolean systemNotificationEnabled = NotificationManagerCompat.from(_applicationContext).areNotificationsEnabled();
394-
SharedPreferences sharedPref = sharedInstance.getMainActivityContext().getSharedPreferences(IterableConstants.SHARED_PREFS_FILE, Context.MODE_PRIVATE);
395-
boolean isNotificationEnabled = sharedPref.getBoolean(IterableConstants.SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED, false);
396-
397393
if (!_firstForegroundHandled) {
398394
_firstForegroundHandled = true;
395+
if (sharedInstance.config.autoPushRegistration && sharedInstance.isInitialized()) {
396+
sharedInstance.registerForPush();
397+
}
399398
fetchRemoteConfiguration();
400399
}
401400

402-
if (sharedInstance.config.autoPushRegistration && sharedInstance.isInitialized() && isNotificationEnabled != systemNotificationEnabled) {
403-
if (systemNotificationEnabled) {
404-
sharedInstance.registerForPush();
405-
} else {
406-
sharedInstance.disablePush();
401+
boolean systemNotificationEnabled = NotificationManagerCompat.from(_applicationContext).areNotificationsEnabled();
402+
SharedPreferences sharedPref = sharedInstance.getMainActivityContext().getSharedPreferences(IterableConstants.SHARED_PREFS_FILE, Context.MODE_PRIVATE);
403+
404+
boolean hasStoredPermission = sharedPref.contains(IterableConstants.SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED);
405+
boolean isNotificationEnabled = sharedPref.getBoolean(IterableConstants.SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED, false);
406+
407+
if (sharedInstance.isInitialized()) {
408+
if (hasStoredPermission && (isNotificationEnabled != systemNotificationEnabled)) {
409+
if (!systemNotificationEnabled) {
410+
sharedInstance.disablePush();
411+
} else {
412+
sharedInstance.registerForPush();
413+
}
407414
}
408-
}
409415

410-
SharedPreferences.Editor editor = sharedPref.edit();
411-
editor.putBoolean(IterableConstants.SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED, systemNotificationEnabled);
412-
editor.apply();
416+
SharedPreferences.Editor editor = sharedPref.edit();
417+
editor.putBoolean(IterableConstants.SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED, systemNotificationEnabled);
418+
editor.apply();
419+
}
413420
}
414421

415422
private boolean isInitialized() {

0 commit comments

Comments
 (0)