PacketTunnelProvider - display an alert to the user (from Extension)

There are some cases at VPNM app (PacketTunnelProvider, for iOS/macOS), in which I want to display an alert to the user from the Extension.

Till recently, I used the function displayMessage() which is now deprecated.

So now I'm using UNUserNotificationCenter, but there are some issues with that:


1. How can I display notifications from the extension, if the user chose not to authorize notifications? Sure, he can choose to do that, but then I don't have any valid way to display notifications from the extension?


2. Is there a way to make the notification persistant? Something like an alert, which will require the user to press an "ok" button.


3. What happens when the device enters sleep mode? The notification will wake the device? Or will it be shown only after the device exit sleep mode? Or maybe it won't be shown at all..?

Answered by DTS Engineer in 399090022

1. How can I display notifications from the extension, if the user chose not to authorize notifications?

You can’t. The trick here is to make your notifications helpful, which encourages the user to leave them enabled.

2. Is there a way to make the notification persistant?

There’s nothing you can at your end. Most notifications do persist in Notification Center, but that’s largely under user control.

3. What happens when the device enters sleep mode?

If the device is truly asleep, your code is not running and hence can’t post a notification.

Are are you talking about screen lock, that is, the device is awake but the screen is locked / off?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

ps DTS is closed 21 Dec through 1 Jan.

Accepted Answer

1. How can I display notifications from the extension, if the user chose not to authorize notifications?

You can’t. The trick here is to make your notifications helpful, which encourages the user to leave them enabled.

2. Is there a way to make the notification persistant?

There’s nothing you can at your end. Most notifications do persist in Notification Center, but that’s largely under user control.

3. What happens when the device enters sleep mode?

If the device is truly asleep, your code is not running and hence can’t post a notification.

Are are you talking about screen lock, that is, the device is awake but the screen is locked / off?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

ps DTS is closed 21 Dec through 1 Jan.

"Are are you talking about screen lock, that is, the device is awake but the screen is locked / off?" - in this case I think the notification should be shown, doesn't it? Isn't this the default behavior?

And as for "device is truly asleep, your code is not running" - when the device is aleep, nothing runs even within the Packet Tunnel Provider? I thought the device do create some traffic even when on sleep mode, to check mails etc..

Before we go further, we need to define some terms:

  • If the device is asleep, the CPUs are stopped and no network traffic is moving [1].

  • Locking the screen does not necessarily put the device to sleep. As an extreme example of this, if you start streaming music and then lock the screen, the device stays awake in order to download and play that music.

In short, locking the screen is necessary for system sleep, but it’s not sufficient.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

ps DTS is closed 21 Dec through 1 Jan.

[1] By the application processor. Various coprocessors may be doing networking stuff, but that’s not visible to you.

Got it. Thanks!

PacketTunnelProvider - display an alert to the user (from Extension)
 
 
Q