Can't connect VPN when I close my App

Hello,


I'm working on a wifi app, there is the VPN function in it. When I keep using my app, I can connect the VPN, but it will be disconnected after I closing the app or move it in the backgroud for a minute.

For resolving this problem, I try to make the app keep alive in the backgroud by using GPS or playing music without sound.....Certainly, I've been rejected😢


Is there anyone can give me some ideas about this:

  1. Is there any method that I can keep my app alive in the background?
  2. Can I let the OS remember the VPN status after closing the app?


Thanks,

Best regards,


L.

Replies

How are you implementing your VPN functionality? There’s two common ways to implement VPN on iOS:

  • Personal VPN — In this case you use

    NEVPNManager
    to configure one of the built-in VPN transports (IKEv2 or IPsec). Both of these will continue working even if the app that configured them is terminated.
  • Custom VPN transports — These are implemented via Network Extension tunnel providers, which continue running even when their host app is terminated.

Share and Enjoy

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

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

Hi eskimo, thanks for your reply.


Yes, I use both of them to implemente my VPN function.


I apologized for describing the problem not so clearly, let me explain the requirement.

My app will calculate the data usage when users access the WiFi and VPN. After accessing WiFi and VPN, users may move my app in the background then surf the internet or watch videos...etc.

To calculate the data I need keep my app alive when it in the background.And I've found my app will not work after a few minute, so that's why I used GPS or music to keep it alive, but it rejected by store. I've also found there were many similar cases about this, but all about using GPS or music to solve it.


Are there any methods can resolve it?


Thanks,

Best regards,


L.

Yes, I use both of them to implemente my VPN function.

Both? Both at the same time? Or do you give the user the option of using either a built-in VPN transport or a custom VPN transport?

When you create a custom VPN transport the actual work is done in a Network Extension tunnel provider, which remains running while the VPN is connected. There’s no reason it couldn’t gather network statistics during that time.

However, in the general case iOS does not allow apps to run indefinitely in the background and, as such, there’s no general solution to the problem you’re trying to solve.

Share and Enjoy

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

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

Thanks for your reply, eskimo.


Maybe there is no way can be done about it. Even I release my app, upload it on store, users start to use it, it also will be killed after move it in the background for a few minutes?

Even I release my app, upload it on store, users start to use it, it also will be killed after move it in the background for a few minutes?

Yes. To repeat, iOS does not allow apps to run indefinitely in the background except under very specific circumstances (such as audio playback), and those background modes are carefully reviewed by App Review per clause 2.5.4 of the App Store Review Guidelines.

Share and Enjoy

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

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

Got it! eskimo!

Thanks for you helping!:)