Open ltemimi opened 2 months ago
Please refer to the Demo project. iOS initialization is not required.
I did thanks and I realise that but it works on android but not ios I get an exception
I get an exception
Object reference not set to an instance of an object.
In the line
var networkInfo = await CrossWifiManager.Current.GetNetworkInfo();
Can you please share the error screenshot?
I have added
var status2 = await Permissions.CheckStatusAsync
to request permissions if needed and now the exception
is nodename nor servname provided, or not known
My device is connected to th Internet.
Thanks
Hi I hope we will find an answer to the ios issue it is expecting DNS and some other parameters.
I also have found another issue in the windows platform the SSD is always null when there is an internet wired connection in addition to the wireless connections. Please help
Can you please share some more details regarding your test environment, with me so that I can reproduce the issue? Also, are you all getting this issues on the demo app ?
Hi
I have a dot net maui app I am using android,ios and windows platform and I am using a WifStaus View and the view model behind it uses code from the github repo. My wifi used for internet and local network is part of an internal IT infrastructure of the a business centre.
As to the windows platform if I disconnect the wired internet netwrok all works fine. So there is a conflict
And most important I am using dot net 8.
I am unable ro run the demo despite the fact I installed dot net 5 as you use netstandard 2
Severity Code Description Project File Line Suppression State Error (active) MSB3644 The reference assemblies for .NETCore,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks MauiWifiManager (uap10.0.19041) C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets 1259
My View model
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Core.ExtensionsLibrary.Services;
using License.Client.Interfaces;
using License.Maui.Interfaces;
using Plugin.MauiWifiManager;
namespace License.Maui.MVVM.ViewModels;
public partial class WifiStatusViewModel(
IInternetConnectionHelper internetConnectionHelper,
IAlertService alertService) : BaseViewModel
{
[ObservableProperty]
// ReSharper disable once InconsistentNaming
// that is how the mvvm community works
private string? currentSsid;
[ObservableProperty]
// ReSharper disable once InconsistentNaming
// that is how the mvvm community works
private bool hasInternet;
[ObservableProperty]
// ReSharper disable once InconsistentNaming
// that is how the mvvm community works
private string ipAddress = "0.0.0.0";
[ObservableProperty]
// ReSharper disable once InconsistentNaming
// that is how the mvvm community works
private string wifiStatus = "Not Checked Yet";
[ObservableProperty]
// ReSharper disable once InconsistentNaming
// that is how the mvvm community works
private Color wifiStatusColour = Colors.Cyan;
public event EventHandler? CheckWifiStatus;
[RelayCommand]
public async Task CheckWifiStatusAsync()
{
try
{
await EnsurePermissionsAsync();
// Step 1: Get current Wi-Fi status and SSID
var networkInfo = await CrossWifiManager.Current.GetNetworkInfo();
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
//it could be null
if (networkInfo is null)
{
WifiStatus = "No Wi-Fi available";
return;
}
CurrentSsid = networkInfo.Ssid ?? "SSD?";
IpAddress = "Network Ip: " + networkInfo.IpAddress.ConvertIntToIpAddress();
// Step 2: Check if the Wi-Fi has internet access
HasInternet = await internetConnectionHelper.IsInternetAvailableAsync();
WifiStatus = (HasInternet, networkInfo.Ssid != null) switch
{
(true, true) => $"Wi-Fi: '{CurrentSsid}' internet access ",
(true, false) => $"Wi-Fi: '{CurrentSsid}' internet access wired?",
(false, true) => $"Wi-Fi: '{CurrentSsid}' no internet access",
(false, false) => $"Wi-Fi: '{CurrentSsid}' no internet access"
};
// fire event
CheckWifiStatus?.Invoke(this, EventArgs.Empty);
}
catch (Exception e)
{
var err = e.Message;
WifiStatus = "Unable to check wifi status";
await alertService.ShowAlert("Unable to check wifi", "Checking Wifi is not allowed!", "OK");
}
}
[RelayCommand]
public async Task OpenWifiSettings()
{
_ = await CrossWifiManager.Current.OpenWifiSetting();
}
private async Task EnsurePermissionsAsync()
{
var status = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();
if (status != PermissionStatus.Granted)
{
_ = await Permissions.RequestAsync<Permissions.LocationWhenInUse>();
}
}
}
Do you mean you were not able to build the Demo project due to reference assemblies?
Correct it asked me to download dot net 5 which I did to no avail. Thanks I am mainly concerned that it does not work with ios due to missing parameters linke DNS etc..
Can you test this example attached at the end here? https://github.com/exendahal/maui_wifi_manager/issues/5
Hi still could not build the pro0ject but I ported the code and the info.plist etc. and
var response = await CrossWifiManager.Current.ScanWifiNetworks(); returns a count of zero it has not detected any wifi
Can you share your implementation into a separate project? I will try to replicate on my machine.
Hi many thanks for the help. I have spent this morning doing a new dot net Maui project and I tested it with windows, android and ios. The wifiStaus is a control (View) so that future app can use it>
Please use your own apple provisioning
1 - Windows platform works if not wired internet is connected . When there is a wired internet connection it overrides all. 2 - Android works well 3 - IOS can't scan wifi network
NOTE: in IOS if the wifi scan returns zero count and one attempt to get a network info an exception is thrown as it cannot find parameters it needs the exception is a socket exception
Please download from here: https://1drv.ms/f/s!Ai1jsiYR5baCnJEqYOPc0-EJHPILCg?e=GNddYx
You can access Wi-Fi networks using the ScanWifiNetworks method only on Android & Windows. Unfortunately, iOS doesn't provide such APIs to scan nearby Wi-Fi.
OK if you use the get info you will get a socket exception as explained before with a screen shot (the if statement that checks for the count > 0 was put only recently to avoid the socket exception. So please feel free to take it out.
So please help with the socket exception on iOS
thanks
Could you please share the iOS version and device model you're currently using?
yes, I am using iPhone 8 iOS 16.7.10
the exception is thrown at var networkInfo = await CrossWifiManager.Current.GetNetworkInfo();
Thanks for the help
Hi I bought an iPhone 11 with latest os still the same issue cannot get the SSD data
Please help
Please share me your demo project. I can't replicate your issue in my side
I did send you my demo project, I think it is better if you send yours. Thanks
I am running the demo project that comes with the project source code. Also, I was not able to get the source code from the link above. Can you please confirm the link attached?
Hi
I used the demo project and it does have the same problem with getting SSD data so it must be the business centre network (though it works on Android) . I will try another location will get back soon Thank.
Yes I removed the demo I sent you I will re-instate it if needed
Hi
I tried on a different network (at home) and got the same results i.e could not get network data. I changed disabled the Wi fi private address and I got the Ip address but not the SSD.
I even tried using native code to no avail. So I have come to the conclusion it is an apple restriction. (some sources quote since version 14)
Your demo gives the same results as my code.
Have you tested your demo on a later version than 14? if it worked were there any changes made to the Wi Fi settings?
Thanks
I have a working demo project on iOS 18 that provides information about the connected Wi-Fi. If you can share any replication steps, I'd be happy to include them in the test cases, as it could be beneficial for others as well.
Hi Sorry for the delay (technology probs)
Her is the link I have not tested with ios 18
Hello, Can you please get 1.0.5 version for the package. Also, please enable access to Wi-Fi information capabilities for your iOS app in App Store Connect.
Ok Thanks it requires Apple approval, I will submit a form and see what happens.
Hi
I am not clear on how to initialise in the app delegate for ios Please help