Skip to content

[Bug]: CAPPlugin listener methods can no longer be overridden in Capacitor 9 (iOS) #8728

In review

Description

@riderx

Capacitor Version

@capacitor/ios 9.0.0-rc.0

Platforms Affected

  • iOS

Current Behavior

Since #8559 (feat!(ios): adopting SwiftUI), notifyListeners(_:data:), notifyListeners(_:data:retainUntilConsumed:), removeListener(_:) and removeAllListeners(_:) moved into the Swift @objc public extension CAPPlugin in CAPPlugin+Bridge.swift. They used to be overridable Obj-C methods on CAPPlugin.

Swift can't override declarations from an extension, so any plugin that overrides them no longer compiles:

override public func removeAllListeners(_ call: CAPPluginCall) {
    // stop native observers, then
    super.removeAllListeners(call)
}

This is a common pattern. Plugins override removeAllListeners to tear down native observers (Firebase Remote Config, Firestore snapshot listeners), and test targets override notifyListeners to capture emitted events. We hit it on @capgo/capacitor-updater and @capacitor-firebase/* while migrating to Capacitor 9.

Expected Behavior

Either keep these methods overridable (open, or move them back into the class body), or provide a documented hook such as an overridable handleListenersRemoved() so plugins can clean up, and note the change in the Capacitor 9 plugin migration guide.

Project Link or Repo

https://github.com/Cap-go/capacitor-updater/tree/v9
https://github.com/Cap-go/capacitor-firebase/tree/v9

Additional Information

Related: #8635 (thread safety for listener state) touches the same code, so a fix could land together with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions