-->

How to turn on VPN from iOS app? (Private APIs OK)

2019-02-07 05:37发布

问题:

When an iOS Device goes into "sleep mode", even a configured VPN is, unfortunately, turned off.

A customer that wants an app for his iPad has to use VPN for security, so anything must be done through VPN. The app has to synchronize a lot, but the iOS device might turn off the VPN by itself. That's why I just need to trigger it again every time i need an internet connection (or keep it alive).

Do any of you guys have anything in mind?

Even using Private API is ok (the app will only be distributed to a customer, not through App Store).

Or using any app like Cisco AnyConnect would do the job.

回答1:

Two ideas:

1) You can create a configuration profile with VPN on demand. This require client certificat authentication though. My guess that if some application will try to access domains or hosts defined in VPN on demand section in sleep mode, VPN will be turned on.

Update: At some moment Apple was sued regarding VPN on demand, so I believe they dropped this feature and after returned it back modified. It's good idea to read this article for iOS 7: http://support.apple.com/kb/ts4550

2) Idea which I offered for this question (iOS6 toggle WiFi on non-jailbroken device). Here is the copy of text from there:

I think it make sense to look at SystemConfiguration.framework.

It has set of API to work with different connection interfaces, which are defined here: http://developer.apple.com/library/mac/#documentation/Networking/Reference/SCNetworkConfiguration/Reference/reference.html

This one is private API.

Update: I believe there were some changes in SystemConfiguration and Apple tightened security around this framework.

3) Apple may grant to some applications additional entitlements, so they can build functionality which no other application can build. As example, VPN client companies (like Cisco) got special entitlements to build what in iOS called "VPN plugins", which is essentially VPN client.



回答2:

Its now possible to do with NetworkExtension framework available in iOS 8 and up. If you go to project settings->capabilities you will find "personal VPN". By turning it on you get the framework added to your project. There is little to no official documentation, but you can check out the WWDC video here https://developer.apple.com/videos/wwdc/2015/?id=717