I have an iOS app (let's call this "APP A") that correctly installs and uses a VPN profile with NEPacketTunnelProvider.
I see this profile in settings ("PROFILE A"), and it is correctly used every time network is requested, because I configured it to do so.
This VPN needs to be always running, per company requirement. If I switch it off in settings, it gets automatically rearmed because of this rule.
let connectRule = NEOnDemandRuleConnect() manager.onDemandRules = [connectRule] manager.isOnDemandEnabled = true
I have another app ("APP B") in the same app group (we manage both of them). APP B has its own VPN profile with NEPacketTunnelProvider ("PROFILE B"), and I see it in settings.
This PROFILE B VPN is only for foreground use, as is started at APP B launch and closed when we switch away (there are some watchdogs, etc). This is by design, and it's ok that it overrules PROFILE A only when using APP B.
When I have PROFILE A active, all works well. It manages all requests and gets reactivated if I switch it off in settings.
When I launch APP B, PROFILE B is correctly selected, activated and used.
But when I return to home/switch away from APP B, PROFILE B deactivates correctly, but profile A never gets activated automatically. Looks like the last - the one with the ✓ in settings - have the precedence now; in this case, it is PROFILE B.
If I switch PROFILE A on by hand in settings, it works of course.
Is there any way to go back to PROFILE A after I close APP B?
I was thinking that being in the same app group could help, but I can't find a way to do it.
I could try to move both profiles to APP B, that will then manage the switching, but I'm not sure if this could be a solution. Apart from this, I would prefer not having even more stuff in APP B, that is mission-critical and with a lot of things going (security, etc.)
Any idea on how I could manage the transition in the best way?
Is there some way to let an app programmatically switch to a profile of another app (same group)?
PS: I was also thinking about using background modes for checking the status (for example Background App Refresh or the new BackgroundTasks), but I think these don't have precise timings, so I will have some time when no VPN will be active.