Skip to content

fix(badges): Fix bug when notification has badge set to zero #1565

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

Merged
merged 1 commit into from
May 29, 2025

Conversation

nan-li
Copy link
Contributor

@nan-li nan-li commented May 23, 2025

Description

One Line Summary

Add additional flag to OSNotification called hasBadge to let us differentiate between null vs 0 badge count by checking this flag.

Details

Motivation

Click to see the before and after clips
set_to_zero_badge_before.mov
set_to_zero_after.mov

Scope

Adds additional boolean property to OSNotification, leaving previous badge property unchanged.

Testing

Unit testing

None

Manual testing

iphone 13 on iOS 18.5 testing different notifications sent with

  • no badge
  • "SetTo" badge count by various values including 0
  • "Increase" badge count by various values including 0

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
    • Badges
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

@nan-li nan-li changed the title fix(type): Make badge NSNumber instead of NSInteger fix(badges): Fix bug when notification has badge set to zero May 23, 2025
* This fixes a bug when a notification had "SetTo" = 0; our check for the existence of notification.badge could not differentiate null vs 0, and we detected 0 as lack of existence.

* Using a flag let's us differentiate between null vs 0 badge count. The payload from APNS will be already be an NSNumber: https://developer.apple.com/documentation/usernotifications/unnotificationcontent/badge?language=objc and we will set the flag if there is a badge
@nan-li nan-li force-pushed the fix/set_badge_number_to_zero_bug branch from b1eedf7 to 50ece19 Compare May 27, 2025 17:22
@nan-li nan-li requested review from jkasten2 and jinliu9508 May 27, 2025 18:05
@jkasten2 jkasten2 mentioned this pull request May 27, 2025
@nan-li nan-li merged commit 48dd3f4 into main May 29, 2025
3 of 4 checks passed
@nan-li nan-li deleted the fix/set_badge_number_to_zero_bug branch May 29, 2025 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants