Fix: Handle null notification array in ResetApplicationIconBadgeNumber - #546
Open
Conversation
Elvin-Thudugala-2degrees
force-pushed
the
elvin-thudugala-2degrees-issue-545-bug-ios-resetapplicationiconbadgenumber-444a56
branch
from
August 9, 2026 23:45
6f2aaf5 to
1dcc0ce
Compare
- Add null check before calling AddRange() in iOS LocalNotificationCenter.cs - Add null check before calling AddRange() in MacCatalyst LocalNotificationCenter.cs - Prevents ArgumentNullException when GetDeliveredNotifications returns null Fixes issue thudugala#545 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Elvin-Thudugala-2degrees
force-pushed
the
elvin-thudugala-2degrees-issue-545-bug-ios-resetapplicationiconbadgenumber-444a56
branch
from
August 9, 2026 23:47
1dcc0ce to
677e149
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Improves null handling in the
ResetApplicationIconBadgeNumber()method by adding an early return in the callback whennotificationArrayis null. This prevents anArgumentNullExceptionwhen iOS'sGetDeliveredNotifications()callback returns a null array instead of an empty array.Why are we doing this? Any context or related work?
The synchronous version of
ResetApplicationIconBadgeNumber()was throwingArgumentNullExceptionbecause the iOS SDK'sGetDeliveredNotifications()callback can pass a null notification array, but the code unconditionally calledAddRange(notificationArray)without null checking. The async version (ResetApplicationIconBadgeNumberAsync()) doesn't have this issue becauseGetDeliveredNotificationsAsync()returns an empty array instead of null.Changes made:
AddRange()inPlatforms/iOS/LocalNotificationCenter.csAddRange()inPlatforms/MacCatalyst/LocalNotificationCenter.csThis approach treats a null notification array gracefully and continues execution as if there are no notifications, which is the correct behavior.
Fixes: #545