public Task<IEnumerable<WifiInfo>> GetAllWifiInfoAsync(
CancellationToken token = new CancellationToken())
{
var tcs = new TaskCompletionSource<IEnumerable<WifiInfo>>();
_semaphore.Wait(token);
Task.Run(() =>
{
var wifiInfo = new List<WifiInfo>();
string[] supportedInterfaces;
var status = CaptiveNetwork.TryGetSupportedInterfaces(out supportedInterfaces);
if (status == StatusCode.OK && supportedInterfaces != null)
{
foreach (var @interface in supportedInterfaces)
{
NSDictionary dict;
CaptiveNetwork.TryCopyCurrentNetworkInfo(@interface, out dict);
var bssid = dict[CaptiveNetwork.NetworkInfoKeyBSSID];
var ssid = dict[CaptiveNetwork.NetworkInfoKeySSID];
wifiInfo.Add(new WifiInfo
{
Bssid = bssid.ToString(),
Ssid = ssid.ToString()
});
}
}
tcs.TrySetResult(wifiInfo);
_semaphore.Release();
}, token);
return tcs.Task;
}
}