Skip to content

fix(badge): clear badge on iOS cold launch when autoClear is enabled#835

Merged
robingenz merged 3 commits into
mainfrom
copilot/fix-capacitor-badge-autoclear-issue
Apr 15, 2026
Merged

fix(badge): clear badge on iOS cold launch when autoClear is enabled#835
robingenz merged 3 commits into
mainfrom
copilot/fix-capacitor-badge-autoclear-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

With autoClear: true, the badge was not cleared on iOS cold launch — only on subsequent background→foreground transitions. The willEnterForegroundNotification is not fired on initial app launch, so the auto-clear logic was never triggered.

Changes

  • BadgePlugin.swift: Call handleOnResume() in load() after initializing the Badge instance, so auto-clear runs on cold launch in addition to foreground re-entry.
override public func load() {
    NotificationCenter.default.addObserver(self, selector: #selector(onResume), name: UIApplication.willEnterForegroundNotification, object: nil)
    self.implementation = Badge(config: badgeConfig())
    self.implementation?.handleOnResume() // also clears on cold launch
}

handleOnResume() is a no-op when autoClear is false, so default behavior is unaffected.

Close #834

Copilot AI changed the title [WIP] Fix capacitor-badge autoClear not clearing badge on iOS cold launch fix(badge): clear badge on iOS cold launch when autoClear is enabled Apr 15, 2026
Copilot AI requested a review from robingenz April 15, 2026 14:21
Copy link
Copy Markdown
Member

@robingenz robingenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Add a one-line comment to add context why we need to call this method at this point

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 15, 2026

@copilot Add a one-line comment to add context why we need to call this method at this point

Done in 38a4fb3. Added: // Handle cold launch, as 'willEnterForegroundNotification' is not fired on initial app launch

Copilot AI requested a review from robingenz April 15, 2026 15:32
@robingenz robingenz marked this pull request as ready for review April 15, 2026 15:50
Copilot AI review requested due to automatic review settings April 15, 2026 15:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes iOS badge autoClear not running on a cold launch by triggering the same resume-handling logic during plugin initialization, ensuring badges are cleared on first app start as well as on background→foreground transitions.

Changes:

  • Invoke handleOnResume() from BadgePlugin.load() immediately after creating the Badge implementation (covers cold launch).
  • Add a Changesets entry to publish a patch release for @capawesome/capacitor-badge.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/badge/ios/Plugin/BadgePlugin.swift Calls handleOnResume() during plugin load so autoClear applies on cold launch.
.changeset/fix-badge-autoclear-ios-cold-launch.md Adds a patch changeset documenting the iOS cold-launch auto-clear fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 15, 2026

Open in StackBlitz

@capawesome/capacitor-age-signals

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-age-signals@835

@capawesome-team/capacitor-android-battery-optimization

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome-team/capacitor-android-battery-optimization@835

@capawesome/capacitor-android-dark-mode-support

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-android-dark-mode-support@835

@capawesome/capacitor-android-edge-to-edge-support

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-android-edge-to-edge-support@835

@capawesome-team/capacitor-android-foreground-service

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome-team/capacitor-android-foreground-service@835

@capawesome/capacitor-app-review

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-app-review@835

@capawesome/capacitor-app-shortcuts

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-app-shortcuts@835

@capawesome/capacitor-app-update

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-app-update@835

@capawesome/capacitor-apple-sign-in

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-apple-sign-in@835

@capawesome/capacitor-asset-manager

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-asset-manager@835

@capawesome/capacitor-background-task

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-background-task@835

@capawesome/capacitor-badge

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-badge@835

@capawesome/capacitor-cloudinary

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-cloudinary@835

@capawesome-team/capacitor-datetime-picker

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome-team/capacitor-datetime-picker@835

@capawesome-team/capacitor-file-opener

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome-team/capacitor-file-opener@835

@capawesome/capacitor-file-picker

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-file-picker@835

@capawesome/capacitor-google-sign-in

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-google-sign-in@835

@capawesome/capacitor-libsql

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-libsql@835

@capawesome/capacitor-live-update

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-live-update@835

@capawesome/capacitor-managed-configurations

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-managed-configurations@835

@capawesome/capacitor-photo-editor

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-photo-editor@835

@capawesome/capacitor-pixlive

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-pixlive@835

@capawesome/capacitor-posthog

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-posthog@835

@capawesome/capacitor-realtimekit

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-realtimekit@835

@capawesome/capacitor-screen-orientation

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-screen-orientation@835

@capawesome/capacitor-screenshot

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-screenshot@835

@capawesome/capacitor-square-mobile-payments

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-square-mobile-payments@835

@capawesome/capacitor-superwall

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-superwall@835

@capawesome/capacitor-torch

npm i https://pkg.pr.new/capawesome-team/capacitor-plugins/@capawesome/capacitor-torch@835

commit: 38a4fb3

@robingenz robingenz merged commit fe76197 into main Apr 15, 2026
10 checks passed
@robingenz robingenz deleted the copilot/fix-capacitor-badge-autoclear-issue branch April 15, 2026 15:56
@github-actions github-actions Bot mentioned this pull request Apr 15, 2026
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: capacitor-badge with autoClear does not clear badge on iOS app cold launch

3 participants