JavaScript Required

We're sorry, but we doesn't work properly without JavaScript enabled.

Many of the apps are secured with VPN because it will protect data from snoopers and mask true location. It hides the online forays in a secure tunnel that outsiders can’t penetrate. VPN used in the app to secure the private server that helps disguise to the location, activity and protects against us from outside incursions. VPN always disables all browsers and other connectivity where users can safely connect to their apps. There is a lot of possibilities where Hackers and Intruders get data using with Wi-Fi connection due to that reason many apps enabled with specific VPN connectivity. There are a lot of VPN apps for iOS which secure tunnel and network for data transfer. Even in iPad settings, there are default VPN settings where we can configure the desired VPN connection and connect the app. For the developers, there are many challenges to handle the error occurred in the app due to VPN connections and fluctuation. Sometimes VPN disconnects but still shows connected in the iOS devices then it will be very strange for the users.

Prerequisite for VPN connection

  • The app should enable with ATS in the Plist file.
  • VPN settings required for proper connection.
  • VPN apps (Pulse secure, Cisco, Tunnel Bear etc.)
  • VPN profile will be download, at the time of connection or sometimes it required to install the profile before connection also.
  • Some companies are using MDM to use VPN like Mobile Iron, Mass360, VMware and AirWatch.

VPN Configuration and Connections in the iOS device with or without using 3rd party apps


App with VPN connection

The below-mentioned screenshot enables with VPN configuration. If VPN is not connected then the app will not work in the Wi-Fi network but sometimes very strange things happen in the app where, VPN showing connected but actually, it’s not connected. It provides, the bad user experience so, Developer needs to keep checking the connectivity continuously. Sometime App will throw 101, 404 and other error code due to VPN issue but the developer’s unable to handle it or identify it in an early stage of development. It will be a very tedious task for the developers and companies handling the app which enable VPN access.


Error handling and connection issue for iOS app with VPN enable

Case 1:

iOS Developers India can handle the VPN using the Network Extension framework which newly introduces in iOS. Developer need to register the notification in the view did load where network reachability can be check, then developers can call the notification to add observer inside Wi-Fi connection where VPN connection will check whether it is connected or not. So different status can handle for VPN issue then at the end of init call developers have to remove, all the observers otherwise it may cause some other issue.

override func viewDidLoad() { super.viewDidLoad() NotificationCenter.default .addObserver(self, selector: #selector(vpnwifiStatus), name: .flagsChanged, object: Network.reachability) updateWifinetwork() } func updateWifinetwork () { switch Network.reachability.status { case .unreachable: case .wifi: notificationVPN = NSNotificationCenter.defaultCenter().addObserverForName(NEVPNStatusDidChangeNotification, object: nil , queue: nil) { notification in let vpnconnectionCheck = notification.object as! NEVPNConnection let status = vpnconnectionCheck.status self.vpnconnectionCheckStatus(status) } case .wwan: } } func vpnconnectionCheckStatus( status:NEVPNStatus ) { switch status { case NEVPNStatus.Invalid: print("VPNConnection: Invalid") case NEVPNStatus.Disconnected: print("VPNConnection: Disconnected") case NEVPNStatus.Connecting: print("VPNConnection: Connecting") case NEVPNStatus.Connected: print("VPNConnection: Connected") case NEVPNStatus.Reasserting: print("VPNConnection: Reasserting") case NEVPNStatus.Disconnecting: print("VPNConnection: Disconnecting") } } @objc func vpnwifiStatus(_ notification: Notification) { updateWifinetwork () }

Case 2:

Other simplest way of handling the VPN issue in the iOS Apps is to check the Wi-Fi first and Call login module inside a Wi-Fi switch case statement. Once the login module called inside WIFI switch case statement then, the error can handle easily. There could be a scenario in which switching of network causing VPN issue because while switching of network VPN will connect and disconnect in the app.

The authorization header will always be nil when the VPN did not connect in the code given below. It means when a user’s tried to login in the app then in the app some parameter send to a server during login the app but, it returns nil when VPN not connected.

if(Network.reachability.status == .reachableViaWifi) { if(self.authorizationHeader == nil) { self.loginWithError(error!) } else if(self.authorizationHeader == nil && error?.code == 101 || error?.code == 404) { self. loginWithError (error!) } else if (error != nil){ self. loginWithError (error!) } else if if (error == nil && self.authorizationHeader != nil ) { self.loginSuceess() } } fileprivate func loginWithError (_ error: NSError, errorMessage: String? = nil) { // create the error message var message: String if errorMessage == nil { if error.code != 0 { message = NSLocalizedString("Unable to connect VPN due to bad network.. Please try again”) } else if (self.authorizationHeader == nil) { message = NSLocalizedString("User doesn't Authenticated Properly because of connectivity issue”) } else { message = NSLocalizedString("Some error occurred. Please try again.", comment: "unknown error") } } else { message = errorMessage! } // show the alert Formats.showSingleActionAlert(title: message, message: "", actionTitle: "OK", actionStyle: .cancel, presentingViewController: self, handler: nil) self.loginViewController.enabledInterface(true) } func loginSuccess(){ print (“login success by connecting VPN”) }