0

I'm just wondering if it's possible for an app to recognize what network you are connected to. I'm making and app where you have to be connected to a specific network before the app lets you use it's functions, but I'm wondering if that is even possible, I am using xamarin but I can program with androidand a little bit ofswift, so I also want to know if it's possible forxamarinto do this, if it's possible with android studio andxcode. I am usingxamarin.forms` by the way.

Nirav Bhavsar
  • 2,133
  • 2
  • 20
  • 24
  • Please realize that "connected to a spesific network" is very weak, since that is easily faked. If it's for convenience of only trying to do something (like setup a gadget if on its setup network) that's fine, but for actual security you should be exchanging cryptographically secure messages with a host on the network, not relying on the network name or gateway MAC. And fortunately that is something you can do with ordinary SSL type networking operations, though if the IP of your authenticiation server is not fixed you may first need to do some host discovery via mDNS or similar. – Chris Stratton Aug 22 '18 at 19:30

3 Answers3

0

This used to be disabled for security reasons but after iOS 4.0 Apple enabled it.

Although this question is for Xcode, the answer can be applied in Xamarin.

This is a sample application built with the feature in question, although it is for Xamarin.Mac

Use function CNCopyCurrentNetworkInfo.

jamesfdearborn
  • 769
  • 1
  • 10
  • 26
0

This is possible but you will have to do native implementations to access the specific platform apis. For Android you will need to use WifiManager (https://developer.android.com/reference/android/net/wifi/WifiManager) and for iOS you could possibly use NEHotspotConfiguration (https://developer.apple.com/documentation/networkextension/nehotspotconfiguration).

I have used WifiManager for Android to connect to a specific Wifi network programmatically.

0

You can use "CrossConnectivity" plugin in Xamarin by adding the package "xam.plugin.connectivity". Below is the code to check connectivity. From the connectionType property you can detect to which network the device is connected and perform operations accordingly. `

CrossConnectivity.Current.ConnectivityTypeChanged += (sender, e) =>
            {
                var wifi = Plugin.Connectivity.Abstractions.ConnectionType.WiFi;
                var cellular = Plugin.Connectivity.Abstractions.ConnectionType.Cellular;
                var connectionTypes = CrossConnectivity.Current.ConnectionTypes;
                if (connectionTypes.Contains(cellular))
                {
                    //Do operations with cellular
                }
                else if (connectionTypes.Contains(wifi))
                {
                    //Do operations with wifi
                }
            };`
subin272
  • 733
  • 6
  • 24