iPhone get SSID without private library

后端 未结 9 790
[愿得一人]
[愿得一人] 2020-11-22 06:00

I have a commercial app that has a completely legitimate reason to see the SSID of the network it is connected to: If it is connected to a Adhoc network for a 3rd party har

相关标签:
9条回答
  • 2020-11-22 06:46

    If you are running iOS 12 you will need to do an extra step. I've been struggling to make this code work and finally found this on Apple's site: "Important To use this function in iOS 12 and later, enable the Access WiFi Information capability for your app in Xcode. When you enable this capability, Xcode automatically adds the Access WiFi Information entitlement to your entitlements file and App ID." https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo

    0 讨论(0)
  • 2020-11-22 06:49

    This code work well in order to get SSID.

    #import <SystemConfiguration/CaptiveNetwork.h>
    
    @implementation IODAppDelegate
    
    @synthesize window = _window;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
    
    CFArrayRef myArray = CNCopySupportedInterfaces();
    CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
    NSLog(@"Connected at:%@",myDict);
    NSDictionary *myDictionary = (__bridge_transfer NSDictionary*)myDict;
    NSString * BSSID = [myDictionary objectForKey:@"BSSID"];
    NSLog(@"bssid is %@",BSSID);
    // Override point for customization after application launch.
    return YES;
    }
    

    And this is the results :

    Connected at:{
    BSSID = 0;
    SSID = "Eqra'aOrange";
    SSIDDATA = <45717261 27614f72 616e6765>;
    

    }

    0 讨论(0)
  • 2020-11-22 06:51

    Here's the short & sweet Swift version.

    Remember to link and import the Framework:

    import UIKit
    import SystemConfiguration.CaptiveNetwork
    

    Define the method:

    func fetchSSIDInfo() -> CFDictionary? {
        if let
            ifs = CNCopySupportedInterfaces().takeUnretainedValue() as? [String],
            ifName = ifs.first,
            info = CNCopyCurrentNetworkInfo((ifName as CFStringRef))
        {
            return info.takeUnretainedValue()
        }
        return nil
    }
    

    Call the method when you need it:

    if let
        ssidInfo = fetchSSIDInfo() as? [String:AnyObject],
        ssID = ssidInfo["SSID"] as? String
    {
        println("SSID: \(ssID)")
    } else {
        println("SSID not found")
    }
    

    As mentioned elsewhere, this only works on your iDevice. When not on WiFi, the method will return nil – hence the optional.

    0 讨论(0)
提交回复
热议问题