MonoTouch WIFI SSID [英] MonoTouch WIFI SSID

查看:111
本文介绍了MonoTouch WIFI SSID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过Monotouch在iPhone上获得连接的WIFI SSID?

is there a possibility to get on an IPhone the connected WIFI SSID with Monotouch?

我发现可以检查Wi-Fi状态,但是无法检查SSID. https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs 有人知道吗? 感谢所有评论

I have found a possibility to check the Wi-Fi States but there is no way to check the SSID. https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs So did anyone know a way? Thanks for all Comments

推荐答案

您可以执行此操作,就像@Jason链接到的示例代码一样.但是,目前在当前版本的MonoTouch中没有针对 CaptiveNetwork 的绑定(但它将包含在将来的beta版本中).

You can do this like the sample code that @Jason linked to. But right now there are no bindings for CaptiveNetwork in the current versions of MonoTouch (but it will be included in a future beta release).

同时,您可以将以下代码复制粘贴到应用程序中以获取SSID.

In the meantime you can copy-paste the following code inside your application to get the 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);
        }
    }

更新:最新的MonoTouch 5.2+版本包括对CaptiveNetwork的支持.上面的代码简化为:

UPDATE: The latest MonoTouch 5.2+ releases includes support for CaptiveNetwork. The above code is simplified to:

using MonoTouch.SystemConfiguration;

static string GetSSID ()
{
    var dict = CaptiveNetwork.CopyCurrentNetworkInfo ("en0");
    return dict [CaptiveNetwork.NetworkInfoKeySSID].ToString ();
}

这篇关于MonoTouch WIFI SSID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆