Skip to content

Fix: Handle null notification array in ResetApplicationIconBadgeNumber - #546

Merged
thudugala merged 1 commit into
thudugala:masterfrom
Elvin-Thudugala-2degrees:elvin-thudugala-2degrees-issue-545-bug-ios-resetapplicationiconbadgenumber-444a56
Sep 9, 2026
Merged

thudugala merged 1 commit into
thudugala:masterfrom
Elvin-Thudugala-2degrees:elvin-thudugala-2degrees-issue-545-bug-ios-resetapplicationiconbadgenumber-444a56

Conversation

@Elvin-Thudugala-2degrees

@Elvin-Thudugala-2degrees Elvin-Thudugala-2degrees commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Improves null handling in the ResetApplicationIconBadgeNumber() method by adding an early return in the callback when notificationArray is null. This prevents an ArgumentNullException when iOS's GetDeliveredNotifications() 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 throwing ArgumentNullException because the iOS SDK's GetDeliveredNotifications() callback can pass a null notification array, but the code unconditionally called AddRange(notificationArray) without null checking. The async version (ResetApplicationIconBadgeNumberAsync()) doesn't have this issue because GetDeliveredNotificationsAsync() returns an empty array instead of null.

Changes made:

  • Added null check with early return in the callback before AddRange() in Platforms/iOS/LocalNotificationCenter.cs
  • Added null check with early return in the callback before AddRange() in Platforms/MacCatalyst/LocalNotificationCenter.cs

This approach treats a null notification array gracefully and continues execution as if there are no notifications, which is the correct behavior.

Fixes: #545

@Elvin-Thudugala-2degrees
Elvin-Thudugala-2degrees force-pushed the elvin-thudugala-2degrees-issue-545-bug-ios-resetapplicationiconbadgenumber-444a56 branch from 6f2aaf5 to 1dcc0ce Compare August 9, 2026 23:45
- 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
Elvin-Thudugala-2degrees force-pushed the elvin-thudugala-2degrees-issue-545-bug-ios-resetapplicationiconbadgenumber-444a56 branch from 1dcc0ce to 677e149 Compare August 9, 2026 23:47
@mos379

mos379 commented Sep 9, 2026

Copy link
Copy Markdown

@Elvin-Thudugala-2degrees any idea when this will be merged?

@thudugala
thudugala merged commit 0f2d140 into thudugala:master Sep 9, 2026
2 checks passed
@mos379

mos379 commented Sep 10, 2026

Copy link
Copy Markdown

Thank you!

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.

[Bug][iOS] ResetApplicationIconBadgeNumber: ArgumentNullException when GetDeliveredNotifications returns null

3 participants