是否有可能在IPhone上使用Monotouch连接WIFI SSID ?
我发现有可能检查Wi-Fi状态,但没有办法检查SSID。https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs有人知道怎么做吗?感谢大家的评论
您可以像@Jason链接到的样例代码那样做。但是目前MonoTouch的当前版本中还没有 captivennetwork 的绑定(但它将包含在未来的测试版中)。
同时,你可以在你的应用程序中复制粘贴以下代码来获得SSID。
using System;
using System.Runtime.InteropServices;
using MonoTouch;
using MonoTouch.CoreFoundation;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
[DllImport (Constants.SystemConfigurationLibrary)]
extern static IntPtr CNCopyCurrentNetworkInfo (IntPtr interfaceName);
static string GetSSID ()
{
IntPtr scl = Dlfcn.dlopen (Constants.SystemConfigurationLibrary, 0);
try {
using (NSString en0 = new NSString ("en0")) {
using (NSDictionary dict = new NSDictionary (CNCopyCurrentNetworkInfo (en0.Handle))) {
using (NSString key = Dlfcn.GetStringConstant (scl, "kCNNetworkInfoKeySSID")) {
return dict [key].ToString ();
}
}
}
}
catch (EntryPointNotFoundException) {
// this is not available when running on the simulator
return String.Empty;
}
finally {
Dlfcn.dlclose (scl);
}
}
UPDATE:最新的MonoTouch 5.2+版本包括对CaptiveNetwork
的支持。以上代码简化为:
using MonoTouch.SystemConfiguration;
static string GetSSID ()
{
var dict = CaptiveNetwork.CopyCurrentNetworkInfo ("en0");
return dict [CaptiveNetwork.NetworkInfoKeySSID].ToString ();
}