We are converting a mobile application from iOS native (Swift) to Xamarin.iOS (so it can eventually be deployed to multiple operating systems).
I am trying to research how to do the following in Xamarin.iOS: 1 - Check if a VPN connection is active/enabled on the iOS device 2 - Bring up the VPN settings screen (or better, enable a specific VPN automatically)
For: 1 - Is this https://learn.microsoft.com/en-us/dotnet/api/networkextension.nevpnstatus applicable? 2 - Same for https://learn.microsoft.com/en-us/dotnet/api/networkextension.netunnelprovidermanager?
Snippets from existing Swift code:
func connectToVpn(){
//mention the connection name instead of exposing the server
//let connectUrl = URL(string: "mobileconnect://connect?name=*********")
let connectUrl = URL(string: "mobileconnect://connect?")
if UIApplication.shared.canOpenURL(connectUrl!) == true
{
UIApplication.shared.openURL(connectUrl!)
}
}
var isVpnConnected : Bool {
let dict = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() as? [String: AnyObject]
guard let keys = dict?["__SCOPED__"]?.allKeys as? [String] else{
return false
}
for key in keys {
if key.contains("tap") || key.contains("tun") || key.contains("ppp") {
return true
}
}
return false
}
Any comments/suggestions/youtube video/blog entry links would be greatly appreciated.
Edit: For 1 - Realized I don't need to check the VPN status, will just ping an internal server/host to see if it responds.