Search code examples
iphoneobjective-cioswifi

Captive Network Usage


I am doing research to find the best way to use the captive network for iOS. It appears that what this does, correct me if I am wrong, is allows the user to input different ssid's and passwords that can be used for automatic login when that network becomes available. If this is so, what would be the best way to accomplish the following, read ssid and password from a user and connect him to that wifi network or is that even possible.

So far all I am doing is pulling out the currently connected network with this:

NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
id info = nil;

for (NSString *ifnam in ifs) {

    NSLog(@"ifnam = %@", ifnam);

    info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge_retained CFStringRef)ifnam);

    if (info && [info count]) {
        break;
    }
}

NSLog (@"SSID: %@", [ info objectForKey"@"SSID" ]);

Solution

  • A "Captive Network" is one like you find in hotels or Starbucks, where the WiFi connection is open but you need to go through a logon or 'I accept the conditions' page in order to connect to any web sites.

    Normally, when you connect to such a network, the IOS Settings app will put up a web form to complete the logon. The purpose of the CN APIs is to allow your app to do the authentication instead of putting up a web form.

    Your question asks about reading the SSID from the user: this doesn't seem too useful since the Settings app already allows users to specify an arbitrary SSID and then to login with a password. The Captive Network API would only be useful if your app knows exactly how to log into the network, in which case it can know the SSID also. You can get the password from the user using the usual NSTextField.

    Note also that IOS doesn't start your app whenever the network is connected: this API only works when your app is already running.