iPhone get a list of all SSIDs without private lib

2019-01-02 16:15发布

问题:

Is it possible the get a list of all available SSIDs on the iPhone without using a private library?

I read iPhone get SSID without private library which is about getting details about the current network.

This answer mentions:

If you jailbreak your device you can use the Apple80211 private framework to look up the available Wi-Fi networks and their signal strength. But that also means your app will get rejected.

Apple has the CaptiveNetwork API but there doesn't seem to be a solution to get a list of all available networks. It seems it's only possible to do so with using the Apple80211 private library, or connecting to all of them.

Am I missing something, or is there no solution?

回答1:

Without the use of private library (Apple80211) you can only get the SSID of the network your device is currently connected to.



回答2:

Since iOS 9, you can use NEHotspotHelper to get a list of SSIDs. But you have to get the com.apple.developer.networking.HotspotHelper entitlement from Apple by sending a request.

Check https://developer.apple.com/documentation/networkextension/nehotspothelper for more infomation.



回答3:

First of All import above two system Header file

import SystemConfiguration/SystemConfiguration.h
import SystemConfiguration/CaptiveNetwork.h

below Function/Method Return SSIDName

-(NSString *)getNetworkId{
    NSString *string = CFBridgingRelease(CNCopySupportedInterfaces());
    NSArray *interfacesArray = CFBridgingRelease(CFBridgingRetain(string));
        if(interfacesArray.count > 0){
            NSString *networkName = [interfacesArray objectAtIndex:0];
            CFStringRef yourFriendlyCFString = (__bridge CFStringRef)networkName;
            NSDictionary *unsafeInterfaceData = CFBridgingRelease(CNCopyCurrentNetworkInfo(yourFriendlyCFString));
            NSString *ssidName = unsafeInterfaceData[@"SSID"];
            return ssidName;
        }
    return @"No network Found";
}


回答4:

Some new APIs have been released as part of the Network Extension in iOS 9 and iOS 11. While neither allows you to scan for networks while your app is running, they both allow you to do related tasks. E.g. you can scan for networks while the Settings Wi-Fi page is running using Hotspot Helper, and you can make it easier for a user to join a network using either of these.

Here's a comparison of the two frameworks.

Hotspot Helper

  • NEHotspotHelper (introduced in iOS 9, WWDC 2015).
  • Requires special permission from Apple.
  • Requires the com.apple.developer.networking.HotspotHelper entitlement.
  • For step-by-step instructions to get this working, see this answer.
  • Allows you to participate in the discovery/authentication to a Wi-Fi network via the Wi-Fi screen in the Settings app. You register to be notified when networks are being scanned (e.g. when the user launches Wi-Fi in the Settings app), and you can automatically pre-fill the password and display an annotation near the network name. The user still needs to tap on the network name to connect, but it won't prompt for a password if you pre-filled it.

Hotspot Configuration

  • NEHotspotConfigurationManager (introduced in iOS 11, WWDC 2017).
  • Does not require special permission from Apple.
  • Requires the com.apple.developer.networking.HotspotConfiguration entitlement.
  • Allows you to initiate a connection to a Wi-Fi network. You give it a list of SSIDs/Passwords that should be connected to while your app is running. It will present a dialog asking the user if they want to connect to the network.



回答5:

Step 1: add the framework SystemConfiguration.framework
Step 2: import following header file

import SystemConfiguration
import SystemConfiguration.CaptiveNetwork

Step 3: Now Use Code:

func getUsedSSID()->String {

       let interfaces = CNCopySupportedInterfaces()

        if interfaces != nil {

            let interfacesArray = CFBridgingRetain(interfaces) as! NSArray

            if interfacesArray.count > 0 {

                let interfaceName = interfacesArray[0] as! String
                let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)! as Dictionary
                let SSIDName = unsafeInterfaceData["SSID"] as! String
                print(SSIDName)/* here print recentally used wifi name*/
                return SSIDName
            }else{
                return "0"
            }
        }else{
            return "0"
        }
    }


回答6:

#import SystemConfiguration#
##import SystemConfiguration.CaptiveNetwork##

 //create variable
  var SSIDNameArray = NSMutableArray()
  var nameArray : NSArray = [];
 // Here function to return all SSIDName
    func getUsedSSID()->NSArray{
        let interfaces = CNCopySupportedInterfaces()
        if interfaces != nil {
            let interfacesArray = CFBridgingRetain(interfaces) as! NSArray
            if interfacesArray.count > 0 {
                for interfaceName in interfacesArray {
                    let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName as! CFString)! as NSDictionary
                    let SSIDName = unsafeInterfaceData["SSID"] as! String
                    self.SSIDNameArray .add(SSIDName)
                }
                nameArray = self.SSIDNameArray .copy() as! NSArray
                return nameArray;
            }else{
                 return nameArray;
            }
        }else{
            return nameArray;
        }
    }


标签: