Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/remove dns ios #14

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/Platforms/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
<key>CFBundleDisplayName</key>
<string>Maui Wifi Manager</string>
<key>CFBundleIdentifier</key>
<string>com.BajraTech.MauiWifiManager</string>
<string>com.company.MauiWifiManager</string>
</dict>
</plist>
8 changes: 4 additions & 4 deletions src/MAUIWifiManager/MauiWifiManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
<PackageId>WifiManager.Maui</PackageId>

<Product>$(AssemblyName) ($(TargetFramework))</Product>
<AssemblyVersion>1.0.4</AssemblyVersion>
<AssemblyFileVersion>1.0.4</AssemblyFileVersion>
<Version>1.0.4</Version>
<PackageVersion>1.0.4</PackageVersion>
<AssemblyVersion>1.0.5</AssemblyVersion>
<AssemblyFileVersion>1.0.5</AssemblyFileVersion>
<Version>1.0.5</Version>
<PackageVersion>1.0.5</PackageVersion>
<PackOnBuild>true</PackOnBuild>
<NeutralLanguage>en</NeutralLanguage>
<DefineConstants>$(DefineConstants);</DefineConstants>
Expand Down
65 changes: 8 additions & 57 deletions src/MAUIWifiManager/WifiNetworkService.apple.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using CoreFoundation;
using CoreLocation;
using CoreLocation;
using Foundation;
using NetworkExtension;
using Plugin.MauiWifiManager.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using SystemConfiguration;
using UIKit;
Expand Down Expand Up @@ -75,15 +72,15 @@ CLLocationManager.Status is CLAuthorizationStatus.AuthorizedAlways ||
{
if (CaptiveNetwork.TryCopyCurrentNetworkInfo(item, out NSDictionary? info) == StatusCode.OK)
{
networkData.StausId = 1;
networkData.Ssid = info?[CaptiveNetwork.NetworkInfoKeySSID].ToString();
networkData.Bssid = info?[CaptiveNetwork.NetworkInfoKeyBSSID].ToString();
networkData.NativeObject = info;
}
}
IPAddress[] ipAddresses = Dns.GetHostAddresses(Dns.GetHostName());
IPAddress ipAddress = ipAddresses.FirstOrDefault(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork);
networkData.IpAddress = BitConverter.ToInt32(ipAddress.GetAddressBytes(), 0);

//IPAddress[] ipAddresses = Dns.GetHostAddresses(Dns.GetHostName());
//IPAddress ipAddress = ipAddresses.FirstOrDefault(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork);
//networkData.IpAddress = BitConverter.ToInt32(ipAddress.GetAddressBytes(), 0);
}
}
return Task.FromResult(networkData);
Expand Down Expand Up @@ -118,56 +115,10 @@ public void Dispose()
public async Task<List<NetworkData>> ScanWifiNetworks()
{
List<NetworkData> wifiNetworks = new List<NetworkData>();

var queue = new DispatchQueue("com.BajraTech.MauiWifiManager");
var options = new NEHotspotHelperOptions { DisplayName = (NSString)"Maui Wifi Manager" };
var handler = new NEHotspotHelperHandler(async (cmd) =>
{
if (cmd.CommandType == NEHotspotHelperCommandType.FilterScanList)
{
foreach (var network in cmd.NetworkList)
{
wifiNetworks.Add(new NetworkData
{
Ssid = network.Ssid,
Bssid = network.Bssid,
SignalStrength = network.SignalStrength
});
}
await Task.Delay(1000); // wait for the scan to complete
var response = cmd.CreateResponse(NEHotspotHelperResult.Success);
response.SetNetworkList(cmd.NetworkList);
response.Deliver();
}
else if (cmd.CommandType == NEHotspotHelperCommandType.Evaluate)
{
// Evaluate the network and set the confidence level
var network = cmd.Network;
network.SetConfidence(NEHotspotHelperConfidence.High);
var response = cmd.CreateResponse(NEHotspotHelperResult.Success);
response.SetNetwork(network);
response.Deliver();
}
else if (cmd.CommandType == NEHotspotHelperCommandType.Authenticate)
{
// Perform custom authentication and deliver the result
var response = cmd.CreateResponse(NEHotspotHelperResult.Success);
response.Deliver();
}
});

var success = NEHotspotHelper.Register(options, queue, handler);
if (success)
{
Console.WriteLine("Registered successfully");
}
else
{
Console.WriteLine("Registration failed");
}

return wifiNetworks;
// ScanWifiNetworks is not supported on iOS
return await Task.FromResult(wifiNetworks);
}


}
}
Loading