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 following issues exist in the development of iOS-side WiFi applications
1.IOS系统WIFI相关的接口很少,大部分接口都是私有接口2.在设备连接上WIFI,没有通过路由器认证前,如果关闭IOS自动弹出的Portal页面,Iphone的WIFI会自动断开3.如何禁止IOS系统自动弹Portal页面4.公共WIFI的名称确定及不确定时的处理办法
This article focuses on applications that can be submitted to the App Store using a public API.
II. Basic Information Acquisition 1. Get the NIC IP
1 2 3 4 5 Span class= "Line-number" >6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
+ (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. Obtaining Network card information
123456789Ten One A - - the - - - + - + A at - - - - - in - |
- (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"]; }
|
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?
放在异步线程,获取到网卡信息再初使化界面,这种方法依然会导致在某些路由器下初次打开界面超长时间的等待,我们的处理方法是,如果3秒内能够获取到相应的配置信息,直接根据配置信息初使化界面,在超过3秒时,给予默认的假WIFI信息,初使化界面。异步线程获取到真实的配置信息后,再重新更新界面。
Iii. difficult issues in the certification Process 1. Portal Disable pop-up with WiFi auto off 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:
www.appleiphonecell.comcaptive.apple.comwww.itools.infowww.ibook.infowww.airport.uswww.thinkdifferent.us
The 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 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 2 3 4 5 6 7 8 9 Ten One A - |
- (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 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 public WiFi solution