capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

bug: Local Notification Actions don't open iOS app

Open dbrils opened this issue 3 years ago • 3 comments

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 2.4.7
  @capacitor/core: 2.4.7
  @capacitor/android: 2.4.7
  @capacitor/electron: 2.4.7
  @capacitor/ios: 2.4.7

Installed Dependencies:

  @capacitor/android 2.4.7
  @capacitor/core 2.4.7
  @capacitor/ios 2.4.7
  @capacitor/cli 2.4.7
  @capacitor/electron not installed

[success] Android looking great! 👌
  Found 4 Capacitor plugins for ios:
    cordova-background-geolocation-lt (4.0.1)
    cordova-open-native-settings (1.5.5)
    cordova-plugin-background-fetch (7.0.1)
    phonegap-plugin-barcodescanner (8.1.0)
[success] iOS looking great! 👌

Platform(s)

iOS

Current Behavior

I have registered local notification action types that navigate me to a certain part of the app. On Android I can click on a notification action and it will open the app and navigate me to the desired location (when the app is running in the background). On iOS I can also click on the notification action but it won't open the application. It will navigate me in the background, because when I open the app it has navigated me to the desired location.

Expected Behavior

I expect the local notification actions to behave the same on iOS and Android. Clicking the notification action on iOS should also open the app, before any of my handlers fire.

Perhaps I'm missing something in the documentation, but the difference in this implementation is quite annoying. If anyone has a solution, please let me know :).

Code Reproduction

Registration of notification action types

public registerActionTypes(): void {
  // Register the notification action types
 const notificationActionTypes: LocalNotificationActionType[] = [
      {
        id: 'VIEW_SOMETHING_NOTIFICATION',
        actions: [
          {
            id: 'VIEW_SOMETHING',
            title: 'View page'
          },
          {
            id: 'DISMISS',
            title: 'Dismiss',
            destructive: true,
          },
        ],
      },
  ]

    LocalNotifications.registerActionTypes({ types: notificationActionTypes });
  }

Handling the notification actions:

  private listenLocalNotificationsActionPerformed(): void {
    LocalNotifications.addListener('localNotificationActionPerformed', (notificationAction: LocalNotificationActionPerformed) => {
      this.ngZone.run(() => {
        this.localNotificationActionTypesService.handleNotificationAction(notificationAction);
      });
    });
  }

  public handleNotificationAction(notificationAction: LocalNotificationActionPerformed): void {
    switch (notificationAction.actionId) {
      case 'VIEW_SOMETHING':
        this.handleViewSomethingAction();
        break;
      default:
        // Per default there would be a 'tap' actionId which is handled automatically by opening the app
        break;
    }
  }

private handleViewSomethingAction(): void {
    this.navController.navigateForward(['home/something']);
}

Other Technical Details

npm --version output: 6.13.4

node --version output: v12.14.1

pod --version output (iOS issues only): 1.10.1

Additional Context

See code example above. I'm using the navContoller to navigate the user to the desired page. I've also found that the App plugin could be used: https://capacitorjs.com/docs/apis/app#openurl, but I would like to avoid this for now, since I don't have deep linking setup yet.

dbrils avatar May 12 '21 08:05 dbrils

In which component you are handling notification actions?

wS2Zth avatar Oct 23 '21 09:10 wS2Zth

Hi there, can you show the code of your schedule notification as well ? I'm struggling to make this Actions list showing, I'm not sure why. I've constructed my actions like you and registered them too.

numerized avatar Jan 23 '22 20:01 numerized

Hi, I do have the opposite case, I want to do something in the background without opening the app.

eg. Approve an event using notification action, then be able to approve another thing from different notification without opening the app.

It works fine on iOS but each action on Android opens the app. What I think would be good is an option that will allow us to choose if we want to open the app or not when we tap the action.

mateuszRybczonek avatar Apr 04 '22 12:04 mateuszRybczonek