use*_*866 6 iphone ssid xamarin.ios ios captivenetwork
是否可以使用Monotouch连接IPhone连接的WIFI SSID?
我发现有可能检查Wi-Fi状态,但无法检查SSID. https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs 所以有人知道吗?感谢所有评论
您可以像@Jason链接到的示例代码那样执行此操作.但是目前MonoTouch的当前版本中没有绑定CaptiveNetwork(但它将包含在未来的beta版本中).
在此期间,您可以在应用程序中复制粘贴以下代码以获取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);
}
}
Run Code Online (Sandbox Code Playgroud)
更新:最新的MonoTouch 5.2+版本包括对CaptiveNetwork.以上代码简化为:
using MonoTouch.SystemConfiguration;
static string GetSSID ()
{
var dict = CaptiveNetwork.CopyCurrentNetworkInfo ("en0");
return dict [CaptiveNetwork.NetworkInfoKeySSID].ToString ();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2160 次 |
| 最近记录: |