Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix badge clearing when calling clearAll #1335

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ NS_SWIFT_NAME(onClick(event:));

+ (void)handleWillShowInForegroundForNotification:(OSNotification *_Nonnull)notification completion:(OSNotificationDisplayResponse _Nonnull)completion;
+ (void)handleNotificationActionWithUrl:(NSString* _Nullable)url actionID:(NSString* _Nonnull)actionID;
+ (BOOL)clearBadgeCount:(BOOL)fromNotifOpened;
+ (BOOL)clearBadgeCount:(BOOL)fromNotifOpened fromClearAll:(BOOL)fromClearAll;

+ (BOOL)receiveRemoteNotification:(UIApplication* _Nonnull)application UserInfo:(NSDictionary* _Nonnull)userInfo completionHandler:(void (^_Nonnull)(UIBackgroundFetchResult))completionHandler;
+ (void)notificationReceived:(NSDictionary* _Nonnull)messageDict wasOpened:(BOOL)opened;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ + (void)presentAppSettings {

+ (void)clearAll {
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
// TODO: Determine if we also need to call clearBadgeCount
[self clearBadgeCount:false];
// removing delivered notifications doesn't update the badge count
[self clearBadgeCount:false fromClearAll:true];
}

+ (BOOL)registerForAPNsToken {
Expand Down Expand Up @@ -686,7 +686,7 @@ + (void)handleNotificationOpened:(NSDictionary*)messageDict
[self launchWebURL:notification.launchURL]; //TODO: where should this live?
}

[self clearBadgeCount:true];
[self clearBadgeCount:true fromClearAll:false];

NSString* actionID = NULL;
if (actionType == OSNotificationActionTypeActionTaken) {
Expand Down Expand Up @@ -755,7 +755,7 @@ + (void)displayWebView:(NSURL*)url {
openUrlBlock(true);
}

+ (BOOL)clearBadgeCount:(BOOL)fromNotifOpened {
+ (BOOL)clearBadgeCount:(BOOL)fromNotifOpened fromClearAll:(BOOL)fromClearAll {

NSNumber *disableBadgeNumber = [[NSBundle mainBundle] objectForInfoDictionaryKey:ONESIGNAL_DISABLE_BADGE_CLEARING];

Expand All @@ -764,8 +764,11 @@ + (BOOL)clearBadgeCount:(BOOL)fromNotifOpened {
else
_disableBadgeClearing = NO;

if (_disableBadgeClearing)
if (_disableBadgeClearing && !fromClearAll) {
// The customer could have manually changed the badge value. We must ensure our cached value will match the current state.
[OneSignalUserDefaults.initShared saveIntegerForKey:ONESIGNAL_BADGE_KEY withValue:[UIApplication sharedApplication].applicationIconBadgeNumber];
return false;
}

bool wasBadgeSet = [UIApplication sharedApplication].applicationIconBadgeNumber > 0;

Expand Down
3 changes: 1 addition & 2 deletions iOS_SDK/OneSignalSDK/Source/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ + (void)init {
}];
*/

[OSNotificationsManager clearBadgeCount:false];
[OSNotificationsManager clearBadgeCount:false fromClearAll:false];
[self startOutcomes];
[self startLocation];
[self startTrackIAP];
Expand Down Expand Up @@ -798,7 +798,6 @@ + (void)load {
*/
- (void)onesignalSetApplicationIconBadgeNumber:(NSInteger)badge {
[OneSignalExtensionBadgeHandler updateCachedBadgeValue:badge];

[self onesignalSetApplicationIconBadgeNumber:badge];
}

Expand Down
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/Source/OneSignalTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ + (void)applicationForegrounded {
// [OneSignal receivedInAppMessageJson:nil];
}

[OSNotificationsManager clearBadgeCount:false];
[OSNotificationsManager clearBadgeCount:false fromClearAll:false];
}

+ (void)applicationBackgrounded {
Expand Down
Loading