Skip to content

Commit

Permalink
Merge pull request #13 from exendahal/fix/remove_dns_ios
Browse files Browse the repository at this point in the history
Remove dns ios
  • Loading branch information
exendahal authored Sep 18, 2024
2 parents b9b71f8 + 810bca2 commit 914d5ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 62 deletions.
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);
}


}
}

0 comments on commit 914d5ba

Please sign in to comment.