CWNetwork get WiFi security mode

475 views Asked by At

I am trying to get security mode with the following code:

main()
{
    CWNetwork *network = [self.scanResults objectAtIndex:row];
    NSLog(@"%@", network);
    NSLog(@"%@", [self securityStringForNetwork:network]);
 }

- (NSString*)securityStringForNetwork:(CWNetwork *)network;
{
    NSString *securityString = @"Unknown";

    if ([network supportsSecurity:kCWSecurityNone])
        securityString = @"None";
    else if ([network supportsSecurity:kCWSecurityWEP])
        securityString = @"WEP";
    else if ([network supportsSecurity:kCWSecurityWPAPersonal])
        securityString = @"WPA Personal";
    else if ([network supportsSecurity:kCWSecurityWPAPersonalMixed])
        securityString = @"WPA Personal Mixed";
    else if ([network supportsSecurity:kCWSecurityWPA2Personal])
        securityString = @"WPA2 Personal";
    else if ([network supportsSecurity:kCWSecurityPersonal])
        securityString = @"Personal";
    else if ([network supportsSecurity:kCWSecurityDynamicWEP])
        securityString = @"Dynamic WEP";
    else if ([network supportsSecurity:kCWSecurityWPAEnterprise])
        securityString = @"WPA Enterprise";
    else if ([network supportsSecurity:kCWSecurityWPAEnterpriseMixed])
        securityString = @"WPA Enterprise Mixed";
    else if ([network supportsSecurity:kCWSecurityWPA2Enterprise])
        securityString = @"WPA2 Enterprise";
    else if ([network supportsSecurity:kCWSecurityEnterprise])
        securityString = @"Enterprise";

    return securityString;
}

The first NSLog displays:

WPA2 Personal

and the second NSLog displays:

WPA Personal Mixed

I realize that supportsSecurity method may return YES on few types of security.

How can I get the exact security mode for the network?

0

There are 0 answers