iOS client de public WiFi solution

Source: Internet
Author: User
Tags bssid

a summary of public WiFi

Now a lot of companies are doing free WiFi, stations, buses, subways, restaurants, as long as there is a dense flow of people have WiFi, free WiFi from the initial Web authentication method also gradually to the Client Authentication mode offset. This article mainly discusses the solution of iOS authentication online.

The development of the iOS-side WiFi application mainly has the following problems:

    1. iOS system WiFi-related interfaces are few, most of the interfaces are private interfaces

    2. If you close the portal page that automatically pops up on iOS, the WiFi will automatically disconnect when the device is connected to WiFi and does not pass the router authentication.

    3. How to disable the iOS system from automatically bouncing portal pages

    4. The determination of the name of public WiFi and the way to deal with it when uncertain

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

Second, basic information access

1. Get the NIC IP

1+ (NSString *) LocalIpAddress2 {3NSString *localip =Nil;4     structIfaddrs *Addrs;5     if(Getifaddrs (&addrs) = =0) {6         Const structIfaddrs *cursor =Addrs;7          while(Cursor! =NULL) {8             if(cursor->ifa_addr->sa_family = = Af_inet && (cursor->ifa_flags & iff_loopback) = =0)9             {TenNSString *name = [NSString stringwithutf8string:cursor->Ifa_name]; One                 if([Name isequaltostring:@"En0"])//Wi-Fi adapter A                 { -Localip = [NSString Stringwithutf8string:inet_ntoa ((structsockaddr_in *) cursor->ifa_addr)sin_addr)]; -                      Break; the                 } -             } -cursor = cursor->Ifa_next; -         } + Freeifaddrs (Addrs); -     } +     returnLocalip; A}

2. Obtaining Network card information

1-(Nsdictionary *) Getwifidic2 {3Cfarrayref MyArray =cncopysupportedinterfaces ();4     if(MyArray! =Nil) {5Cfdictionaryref mydict = Cncopycurrentnetworkinfo (Cfarraygetvalueatindex (MyArray,0));6         if(Mydict! =Nil) {7Nsdictionary *dic = (nsdictionary*) cfbridgingrelease (mydict);8             returndic;9         }Ten     } One     returnNil; A } -   --(NSString *) Getbssid the { -Nsdictionary *dic =[self getwifidic]; -     if(dic = =Nil) { -         returnNil; +     } -     returndic[@"BSSID"]; + } A   at-(NSString *) Getssid - { -Nsdictionary *dic =[self getwifidic]; -     if(dic = =Nil) { -         returnNil; -     } in     returndic[@"SSID"]; -}

* * Precautions * *

In the actual test, to obtain the network card information **getwifidic** method, on some routers take a long time (more than 10 seconds), if placed directly in the main thread, will cause the interface card dead. In certification-related applications, the company's routing is judged by the BSSID on the network card (e.g., the company's network that starts with a specific 3d:e6:c3). SSID, Bssid if it is necessary to obtain information when the application is launched (this is the application of our company), how to deal with it at this time?

Put on the asynchronous thread, get to the network card information and then the initial interface, this method will still lead to the first open interface under some routers for a long time to wait, our processing method is, if you can obtain the corresponding configuration information in 3 seconds, directly according to the configuration information of the initial interface, in more than 3 seconds, Give the default fake WiFi information, the initial interface. After the asynchronous thread obtains the actual configuration information, it updates the interface again.

Iii. The thorny issues in the certification process

1. Portal disable pop-up with WiFi auto shutdown problem

Normally, the user uses the iphone to connect with a portal-certified router, and after the connection is successful, the iOS system randomly chooses to connect to the specified URL (for example: Www.itools.info) in the existing list to test whether the current router requires portal authentication. In the network that requires portal authentication, the system will pop up the portal page, and at this time, if the portal page is turned off, or if you switch directly to other applications, the WiFi network will automatically disconnect (without giving the client authentication opportunity ^_^).

Our solution is to have the router whitelist, let the router release all the portal test IP, the following is the domain name of the test:

1 www.appleiphonecell.com 2 captive.apple.com 3 Www.itools.info 4 Www.ibook.info 5 www.airport.us 6 www.thinkdifferent.us

The corresponding IP address:

1 23.207.103.912 23.33.54.183 23.44.167.914 23.67.183.915 96.7.103.916 23.42.71.917 23.34.105.2118 23.59.167.919 23.42.184.50Ten 23.47.232.190 One 23.77.23.91 A 23.194.87.91 - 23.61.91.190 - 23.218.12.50 the 23.2.38.95 - 23.46.135.91 - 172.225.213.179 - 218.205.66.94 + 23.64.251.249 - 23.58.250.189

Add all of the above IP to the router's whitelist, you can solve the problem of the iphone disconnected WiFi, but also does not automatically eject the portal page, the user opened the browser will not be redirected to the portal page.

2. WiFi Name Determination Solution

If the company deploys the public WiFi name determines the situation, it is relatively simple, do not need to configure the white list can also be guaranteed to keep WiFi open, specifically, when the program starts, the iOS system to register the SSID, the method is as follows:

1- (void) Registernetwork: (NSString *) SSID2 {3NSString *values[] ={SSID};4Cfarrayref arrayref = Cfarraycreate (Kcfallocatordefault, (void*) values,5(Cfindex)1, &kcftypearraycallbacks);6     if(Cnsetsupportedssids (arrayref)) {7Nsarray *ifs = (__bridge_transferID) cncopysupportedinterfaces ();8Cnmarkportalonline (__bridge cfstringref) (ifs[0]));9NSLog (@"%@", IFS);Ten     } One   A   -}

Iv. Summary

Apple for WiFi this public API very little, in the development of public WiFi applications will encounter a variety of problems, above is the use of non-private API some solutions, if you have a better way, welcome message sharing. If a company has an enterprise account, it can handle most of the requirements by calling the private API.

iOS client de public WiFi solution

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.