On the iPhone, is it possible to find out which WI

2019-02-07 05:18发布

问题:

If yes, can we also get additional information about the network configuration?

One useful way to do this could be getting the SSID of the current network. Is there an API to do that?

Update: I found a similar question here:

Can the iPhone SDK obtain the Wi-Fi SSID currently connected to?

回答1:

(Separate answer to preserve history etc.)

It looks like you might not be able to determine the SSID of the WLAN to which you're connected, at least in an app that will go into the App Store. These people use a private API - Preferences.framework - to get to the details of the WLAN (like "is it hidden?" "What's the name?" etc.).



回答2:

Try following method:

#import <SystemConfiguration/CaptiveNetwork.h>

NSString *wifiName = @"Not Found";
CFArrayRef myArray = CNCopySupportedInterfaces();

if (myArray != nil) {

    CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));

    if (myDict != nil) {
        NSDictionary *dict = (NSDictionary*)CFBridgingRelease(myDict);

        wifiName = [dict valueForKey:@"SSID"];

    }  
}

NSLog(@"wifiName:%@", wifiName);


回答3:

Can't comment, but this might be a duplicate:

Accessing iPhone WiFi Information via SDK

Answer seems to be no. I've done my own research on this and have been unable to find a supported way of getting the SSID.



回答4:

Have you looked at the Reachability sample app?

Edit: The Reachability app demonstrates the use of the SystemConfiguration framework to show whether your phone's connected to the internet and, if so, how.

It further allows you to distinguish between a local WiFi connection and not (+[Reachability reachabilityForLocalWiFi]).

Regarding the meat of your question, you'll have to consult the phone's ARP table. This answer shows you how to do just that.