How to consume notifications generated by NEPacketTunnelProvider on containing app

We're developing an application which involves Packet Tunnel Provider extension. Inside the extension we connect to remote server to get tunnel config profile and authentication parameters, followed by tunnel creation.

If we are not able to establish the tunnel, we would like to notify the user via the containing app. It is possible the tunnel extension is running when the containing app is not running, so we decided to send a notification (via UserNotifications) to achieve the same.

Requirement is that:

  • If containing app is in foreground, notification should not be displayed, app handles whatever is required
  • If app is in foreground, when user clicks on the notification, app should come into foreground and handle it
  • If app is not running, app should launch and handle the notifications
  • If user launchers app/app comes into foreground, app handles all shown notifications and clears them

We are trying to achieve this by implementing the UNUserNotificationCenterDelegate in AppDelegate of containing app.

Now all above requirements are fulfilled when the notification is published by the containing app, but when published by the NEPacketTunnelProvider extension, the notification appears but clicking on it does not call the appropriate delegate function in containing app.

We want to support MacOS 10.15 and above if possible. We are testing on MacOS 12.4 and 12.3.2 for now.

Please help with same or suggest a better way of notifying the user that some action is required and containing app needs to be opened.

Now all above requirements are fulfilled when the notification is published by the containing app, but when published by the NEPacketTunnelProvider extension, the notification appears but clicking on it does not call the appropriate delegate function in containing app.

Right, if I am understanding you correctly, you will always want to land the notification in your container app because that has the UI for the user to interact with. The Network Extension does not. If your NEPacketTunnelProvider lets your server know to send a notification to only the container app does this work?

@meaton Any update on how to achieve above? Please note we are using local notifications and not pushed notifications from remote server. Or if there is a different way we can achieve our objective here?

This issue is still present today in macOS Sonoma. I filed FB13385867 with steps to reproduce.

How to consume notifications generated by NEPacketTunnelProvider on containing app
 
 
Q