JoinOnce does not work properly.
In iPad 9 + iPadOS 16.1.1, turning our app to Sleep with JoinOnce = false does not disconnect the Wi-Fi.
But on the iPad mini 6 + iPadOS 16.1.1, setting JoinOnce = false and turning our app to Sleep would disconnect the Wi-Fi.
Maybe I'm using the NEHotspot Configuration Manager incorrectly?
Well folks, is my code correct?
We develop with Xamarin.
inline-code
//----------------------------------------------------------------------
// Interface(IWifiConnector)
//----------------------------------------------------------------------
/// <summary>
/// Request a connection.
/// </summary>
/// <param name="ssid">SSID</param>
/// <param name="securityKey">Security key</param>
/// <param name="notifyResultAction">Connection result notification action (Request result, connection in progress)</param>
public void RequestConnect(
string ssid,
string securityKey,
Action<UsCommResult, bool> notifyResultAction)
{
// If you are already connected to the specified SSID, notify the connection result and exit
string currentSsid = GetCurrentSsid();
if ((currentSsid != null) && (currentSsid == ssid)) {
// WiFi connection complete
notifyResultAction(UsCommResult.Ok, false);
return;
}
// To use NEHotspotConfiguration Manager and NEHotspotConfiguration, enable "Hotspot" in the provisioning profile and "Entitlements.plist"
var wifiManager = new NEHotspotConfigurationManager();
var wifiConfig = new NEHotspotConfiguration(ssid, securityKey, false/*isWEP*/);
wifiConfig.JoinOnce = false;
wifiConfig.LifeTimeInDays = 1;
wifiManager.ApplyConfiguration(wifiConfig, (error) => {
if (error != null) {
// WiFi connection error
// ( Even when connected, the message is stored in error, so check connected before execution.)
notifyResultAction(UsCommResult.WifiConnectionFailure, false);
}
else {
UsDeviceModel.GetInstance().IsAutoFreezeOFF = true;
// Start WiFi connection
notifyResultAction(UsCommResult.Ok, true);
}
});
}
/// <summary>
/// Get the SSID of the current connection.
/// </summary>
/// <returns>SSID(Unconnected:null)</returns>
public string GetCurrentSsid() {
// To use CaptiveNetwork, enable the provisioning profile and "Access WiFi Information" in "Entitlements.plist"
string[] interfaces;
CaptiveNetwork.TryGetSupportedInterfaces(out interfaces);
if ((interfaces == null) || (interfaces.Length <= 0)) {
return null;
}
try
{
NSDictionary networkInfo;
CaptiveNetwork.TryCopyCurrentNetworkInfo(interfaces[0], out networkInfo);
if (networkInfo == null) {
return null;
}
string ssid = networkInfo[CaptiveNetwork.NetworkInfoKeySSID].ToString();
return ssid;
}
catch (Exception ex) {
return null;
}
}
Topic:
App & System Services
SubTopic:
Networking
Tags: