2011-12-29 8 views
6

Monotouchで接続されたWIFI SSIDをiPhoneに接続する可能性はありますか?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を使用してください。 –

関連する問題