Public WIFI solution for IOS clients and ioswifi Solution

Source: Internet
Author: User
Tags bssid

Public WIFI solution for IOS clients and ioswifi Solution
I. Overview of Public WIFI

Nowadays, many companies are doing free WIFI, such as stations, buses, subways, and restaurants. WIFI is available in areas with intensive flow of personnel, free WIFI has gradually shifted from the original Web authentication method to the client authentication method. This article mainly discusses solutions for accessing the Internet through IOS authentication. The following problems exist in the development of WIFI applications on IOS:

1. there are few Wi-Fi-related interfaces in IOS, most of which are private interfaces. 2. if you disable the Portal page automatically displayed on IOS before the device is connected to wi-fi and fails to pass router authentication, the Iphone WIFI will be automatically disconnected 3. how to disable the IOS system to automatically play the Portal page 4. solutions for determining the public WIFI name and uncertainty

This article focuses on applications that can be submitted to the App Store by using public APIs.

2. obtain basic information 1. Obtain the IP address of the NIC
12345678910111213141516171819202122
+ (NSString *)localIPAddress{    NSString *localIP = nil;    struct ifaddrs *addrs;    if (getifaddrs(&addrs)==0) {        const struct ifaddrs *cursor = addrs;        while (cursor != NULL) {            if (cursor->ifa_addr->sa_family == AF_INET && (cursor->ifa_flags & IFF_LOOPBACK) == 0)            {                NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];                if ([name isEqualToString:@"en0"]) // Wi-Fi adapter                {                    localIP = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr)];                    break;                }            }            cursor = cursor->ifa_next;        }        freeifaddrs(addrs);    }    return localIP;}
2. Obtain Nic Information
123456789101112131415161718192021222324252627282930
- (NSDictionary *)getWIFIDic{    CFArrayRef myArray = CNCopySupportedInterfaces();    if (myArray != nil) {        CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));        if (myDict != nil) {            NSDictionary *dic = (NSDictionary*)CFBridgingRelease(myDict);            return dic;        }    }    return nil;}- (NSString *)getBSSID{    NSDictionary *dic = [self getWIFIDic];    if (dic == nil) {        return nil;    }    return dic[@"BSSID"];}- (NSString *)getSSID{    NSDictionary *dic = [self getWIFIDic];    if (dic == nil) {        return nil;    }    return dic[@"SSID"];}

Notes

Obtain the NIC information during the actual test.GetWIFIDicMethod, it takes a long time (more than 10 seconds) on some routers. If it is directly placed in the main thread, the interface will die. In Authentication-related applications, the company determines whether a route belongs to the company based on the BSSID on the NIC (for example, a network established for the company starting with a specific 3d: e6: c3. If the SSID and BSSID are the information that must be obtained when the application is started (this is the application in our company), what should we do at this time?

Put it in an asynchronous thread, get the NIC information, and then initialize the interface. This method will still lead to a long wait for some routers to open the interface for the first time. Our solution is, if the corresponding configuration information can be obtained within 3 seconds, the default false WIFI information will be provided directly based on the initial configuration information interface. The asynchronous thread obtains the real configuration information and then updates the interface again.
Iii. Difficult issues during authentication 1. Portal disabling pop-up and WIFI disabling

Normally, the user uses an Iphone to connect to a router with Portal authentication. After the connection is successful, the IOS system will randomly select a URL (for example, www.itools.info) from the existing list) to test whether the current vro requires Portal authentication. In a network that requires Portal authentication, the Portal page is displayed. If you disable the portal page or directly switch to another application, the Wi-Fi network will be automatically disconnected (no client authentication opportunity will be given ).

The solution is to whitelist the routers and allow the routers to release all IP addresses tested on the Portal. The following are the tested domain names:

www.appleiphonecell.comcaptive.apple.comwww.itools.infowww.ibook.infowww.airport.uswww.thinkdifferent.us

Corresponding IP Address:

23.207.103.9123.33.54.1823.44.167.9123.67.183.9196.7.103.9123.42.71.9123.34.105.21123.59.167.9123.42.184.5023.47.232.19023.77.23.9123.194.87.9123.61.91.19023.218.12.5023.2.38.9523.46.135.91172.225.213.179218.205.66.9423.64.251.24923.58.250.189

Add all the above IP addresses to the vro whitelist to solve the problem of Iphone disconnection from WIFI. However, the Portal page does not pop up automatically. Users can redirect to the Portal page only when they open the browser.

2. How to Determine the WIFI name

If the company deploys a public WIFI name, it will be relatively simple. You do not need to configure the above whitelist to ensure that WIFI is continuously enabled. The specific method is that when the program is started, register the SSID with the IOS system as follows:

12345678910111213
- (void)registerNetwork:(NSString *)ssid{    NSString *values[] = {ssid};    CFArrayRef arrayRef = CFArrayCreate(kCFAllocatorDefault,(void *)values,                                        (CFIndex)1, &kCFTypeArrayCallBacks);    if( CNSetSupportedSSIDs(arrayRef)) {        NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();        CNMarkPortalOnline((__bridge CFStringRef)(ifs[0]));        NSLog(@"%@", ifs);    }}
Iv. Summary

Apple has very few public APIs for WIFI and will encounter various problems when developing public WIFI applications. The above are some solutions for using non-private APIs. If you have better solutions, you are welcome to share your message. If a company has an enterprise account, you can call a private API to handle most of the requirements.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.