Akash
Akash

Reputation: 191

How to get all available wifi network name listings in iOS

I need to create an app that can get a list of all available wifi networks' names and information on their iPhone, and when the user clicks on some network they should connect to it. Can I do this, and how?

Upvotes: 18

Views: 31353

Answers (3)

Rajeev Udayan
Rajeev Udayan

Reputation: 310

Yes it is possible.You need to complete a questionnaire at https://developer.apple.com/contact/network-extension, and then you can use NEHotspotHelper to return a list of hotspots.

Upvotes: 1

user7718859
user7718859

Reputation:

By doing some research I found that:
It is NOT possible in iOS to scan all nearby SSID. We can only get currently connected wifi SSID. If we somehow do this with any private library, App will be rejected by Apple. Some helpful Links I want to share -

You can get connected wifi SSID by these methods:
Swift (3 and 4) -

import SystemConfiguration.CaptiveNetwork

func fetchSSIDInfo() -> String? {
        var ssid: String?
        if let interfaces = CNCopySupportedInterfaces() as NSArray? {
            for interface in interfaces {
                if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
                    ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
                    break
                }
            }
        }
        return ssid
    }

Objective-C -

#import <SystemConfiguration/CaptiveNetwork.h>

+(NSString*)fetchSSIDInfo {

    NSArray *ifs = (__bridge_transfer NSArray *)CNCopySupportedInterfaces();

    NSDictionary *info;

    for (NSString *ifnam in ifs) {

        info = (__bridge_transfer NSDictionary *)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);

        if (info && [info count]) {

            return [info objectForKey:@"SSID"];
            break;
        }
    }

    return @"No WiFi Available";
}

Upvotes: 2

Rashed
Rashed

Reputation: 2425

It is not possible to get all the available wifi networks names and information. BUT it is only possible to get the SSID (SSID is simply the technical term for a network name) of the network that you are currently connected to.

This class will show only the wifi network name you are connected to -

    import UIKit
    import SystemConfiguration.CaptiveNetwork

    class ViewController: UIViewController {

        @IBOutlet weak var label: UILabel!

        override func viewDidLoad(){
            super.viewDidLoad()
            let ssid = self.getAllWiFiNameList()
            print("SSID: \(ssid)")
        }
        func getAllWiFiNameList() -> String? {
            var ssid: String?
            if let interfaces = CNCopySupportedInterfaces() as NSArray? {
            for interface in interfaces {
            if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
                        ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
                        break
                    }
                }
            }
            return ssid
        }
    }

OUTPUT- (Network name where i am connected to )

enter image description here

To test this you need a physical device (iPhone) connected to your pc.

Upvotes: 10

Related Questions