What is the correct way to display errors in PacketTunnelProvider?

I'm subclassing NEPacketTunnelProvider and need to know how to alert the user of error conditions. Sometimes the error is the user's fault (like wrong credentials), so it's important we tell them what went wrong so they can fix it.

I'm not sure of the correct way to do this. It seems dirty and probably impossible to show something like a UIAlertView directly, not to mention it's deprecated.


Documentation states that we should call -[NEPacketTunnelProvider cancelTunnelWithError:], which I am doing, but it does not provide any feedback to the user. Neither does passing an error object to the completion handler of -[NEPacketTunnelProvider startTunnelWithOptions:completionHandler:].


What is the correct way to display an error to the user in this case?

It may be deprecated, but it's replacement, UIAlertController, works as intended, and is your friend in this case, I think.

Setting aside what part of your code generates the error, what you are asking is how to design your user interface. How you choose to display errors depends on that design. In some cases an error graphic that the user can tap on for more information can work. In other cases where the error must be resolved before continuing, an alert controller could be helpful. Some errors where you want to provide plenty of information and possibly a way to resolve the error could warrant a full view controller. It is up to you to determine what works best in your application for each potential error condition.

Thanks for your replies, but I have a feeling they're not the correct answer. The reason being, my app is not necessarily even running at the time the packet tunnel provider is running (this is an app extension). It works fine to kill the app and manually start the tunnel from the iOS Settings.app

Since the user could be doing literally anything at the time this error can occur, designing or even displaying my own UI seems bad practice, if not impossible, and is probably out of the question. I'm quite sure this must be handled by a layer outside of my app.

Sorry, I realise I'm potentially missing a crucial piece of information - I'm talking about an error occurring inside of the app extension (packet tunnel provider), not an error occurring inside my main application.

Yep, that is important. Hmm, generally there is some kind of configuration utility which could be a place to display the error, or you can always output to the log if they are technical users. This is outside my area of expertise. Hopefully someone with experience developing this can guide you in the right direction.

Any chance you figured it out? Im having the same problem - Im running app extension and I need to inform the users about error. Problem is I dont have the "main" app, just the extension.

Nope. I filed a Radar but it was closed as duplicate. Obviously I can't see the contents of the "original" bug report.


Hoping Eskimo can chime in here 🙂

Hoping Eskimo can chime in here

I can certainly take a look at those bugs. What is your bug number and the number the original?

Share and Enjoy

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

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

Do you ask about how the container app(UI) and app extension(VPN) communicate with each other ?


In the perspective of OS, your UI and your app extension are two different processes, you should use IPC to communicate.


The NetworkExtension only supply some necessary APIs which is no enough, so you need to use other machnism to do that.


I also implement my Custom VPN, and i use some IPC to help communicate information.

I did it too, but what about the case when the user initiated the VPN and killed the containing app ?
If the VPN got an error, and you need to close the tunnel, how do you notify this to the user?

What is the correct way to display errors in PacketTunnelProvider?
 
 
Q