NEHotspotConfigurationManager - iPhone internal error

Hello everyone, I tried to make my iPhone change the Wifi network using Xamarin.iOS.

I have already contacted the Xamarin service who told me that the programming is translated 1:1 with Swift and that the problem is an internal iPhone error.

My code is:

public class ConnectToWifi : IConnectToWifi
{
     string SSID;
     public string Password;
     public IPAddress ServerAddress;
     int ServerPort = -1;
     public bool isConnect = true;
     public CFSocket Socket;
     public CFSocket ServerSocket;
     NEHotspotConfigurationManager wifiManager;
     
     public ConnectToWifi()
     {

         wifiManager = new NEHotspotConfigurationManager();
     }

     public async Task<bool> Connect(string Ip, int Port)
     {
         isConnect = false;
         ServerPort = Port;
         try
         {
             ServerAddress = new IPAddress(IPAddress.Parse(Ip).GetAddressBytes());
             Socket = new CFSocket();
                   NEHotspotConfigurationManager.SharedManager.GetConfiguredSsids((listWifi) =>
                   {
                       if (listWifi != null)
                       {
                           foreach (string ssid_selected in listWifi)
                           {
                               
                               if (ssid_selected == SSID)
                               {
                           NEHotspotConfigurationManager.SharedManager.RemoveConfiguration(SSID);
                               }
                           }
                       }
                   });
             NEHotspotConfiguration wifiNetwork = new NEHotspotConfiguration(SSID, Password, false);
             wifiNetwork.JoinOnce = true;
             wifiManager.ApplyConfiguration(wifiNetwork, (error) =>
                 {
                     if (error != null)
                     {
                         System.Diagnostics.Debug.Write(error.Description);
                     }
                     else
                     {
                         System.Diagnostics.Debug.Write("Connected");
                     }
                     isConnect = true;
                 });
         }
         catch (CFSocketException exception)
         {
             System.Diagnostics.Debug.WriteLine("Ho ricevuto questo errore nella Connect: " + exception.Message);
             return isConnect;
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine("Ho ricevuto questo errore nella Connect: " + ex.Message);
             return isConnect;
         }
         return isConnect;      
     }
}

Upon connection comes the wifiManager function.ApplyConfiguration returns the following error:

ErrorDomain=NEHotspotConfigurationErrorDomain Code=8 "internal error." UserInfo={NSLocalizedDescription=internal error.}

I have an iPhone X with iOS 14.6  and a MacBook with:

  • MacOS Big Sur 14.5;
  • Xcode Version 12.5.1;
  • Visual Studio for Mac 8.10.7;
  • Xamarin.iOS 14.20.0.24 (Visual Studio Community);

In my AppID profile and in the Entitlements.plist file I have activated the following services:

  • Access WiFi Information;
  • Fonts;
  • Hotspot;
  • Network Extensions;

Thank you very much for helping!

Regards,

Giacomo Ferrera

Replies

I have already contacted the Xamarin service who told me that the programming is translated 1:1 with Swift and that the problem is an internal iPhone error. Upon connection comes the wifiManager function.ApplyConfiguration returns the following error: ErrorDomain=NEHotspotConfigurationErrorDomain Code=8 "internal error." UserInfo={NSLocalizedDescription=internal error.}

I do not claim to be an expert on Xamarin or C#, but it looks like you are creating a NEHotspotConfiguration and then applying that configuration with an internal error. Now, the best way to reduce what is happening here is to just create a blank app with the stack values that you know to exist for the SSID and password of the network and see if that works out for you. From there, you should be able to integrate this code path into your project. If it fails after you integrate it back into your project then you know you have other code level issues. For a Swift based example of how NEHotspotConfiguration works, checkout the sample for Configuring a Wi-Fi Accessory to Join the User’s Network.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com