9

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" ]);
4

2 に答える 2

13

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.

于 2012-09-12T20:45:33.747 に答える
1

I handled this generically with a 2 step process. The first test was a general reachability test, that fails if no network present. On failure I alert the user that a network is required. IF network present, as the second step I send a request to my sever. If it times out, I alert the user to check the network connection it needs attention.

于 2012-09-17T21:34:24.690 に答える