Skip to content

localNotificationActionPerformed only works on iOS if the app is already in the background #2330

@d0minYk

Description

@d0minYk

Bug Report

Plugin(s)

@capacitor/push-notifications: 6.0.0

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 7.1.0
  @capacitor/core: 7.1.0
  @capacitor/android: 7.1.0
  @capacitor/ios: 7.1.0

Installed Dependencies:

  @capacitor/cli: 6.1.0
  @capacitor/core: 6.1.0
  @capacitor/ios: 6.1.0
  @capacitor/android: 6.1.0

Platform(s)

iOS

Current Behavior

When the app is not running and a push notification is tapped, the iOS pushNotificationActionPerformed handler does not pick up the tapped notification, but android does. When a push notification is tapped while the app is in the background both platforms trigger the listener.

Expected Behavior

iOS would also trigger pushNotificationActionPerformed, and not just Android.
In the above code the alert with "2" is only shown on android when launching the app initially, if launching from running state (backgrounded) it will alert "2" on both iOS and Android

Code Reproduction

    if (isPlatform("ios") || isPlatform("android")) {
      PushNotifications.addListener('pushNotificationReceived', (notification) => { alert("1"); this.handleNotification(notification, false, true) } );
      PushNotifications.addListener('pushNotificationActionPerformed', (notification) => { alert("2"); this.handleNotification(notification.notification, true, true) } );
    }

Other Technical Details

Followed all instructions on the plugin details page, AppDelegate file contains the required

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: deviceToken)
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
  NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
}

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions