2011-12-29 4 views
6

Monotouch로 연결된 WIFI SSID를 아이폰에 연결할 가능성이 있습니까?MonoTouch WIFI SSID

Wi-Fi 상태를 확인할 수있는 가능성을 발견했지만 SSID를 확인할 방법이 없습니다. https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs 그렇다면 누구나 방법을 알고 있었습니까? 모든 의견을 주셔서 감사합니다.

+1

[Obj-C] [1] 사용 예는 다음과 같습니다. MT에서 비슷한 접근법을 사용할 수 있어야합니다. [1] : http://stackoverflow.com/questions/5198716/iphone-get-ssid-without-private-library – Jason

답변

6

@ Jason이 (가) 연결된 샘플 코드처럼 할 수 있습니다. 하지만 지금은 현재 버전의 MonoTouch에서 CaptiveNetwork에 대한 바인딩이 없습니다 (단, 향후 베타 버전에 포함될 예정입니다).

그 사이에 애플리케이션 내부에 다음 코드를 복사하여 붙여 넣어 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(); 
} 
+2

CopyCurrentNetworkInfo는 MT 6.0.6 이제 사용되지 않습니다. 대신 TryCopyCurrentNetworkInfo를 사용하십시오. –