简体   繁体   中英

Detect that a WiFi network needs authentication

I am writing an iOS app that used a HTTP web service to get its data. If a user is connected to a WiFi network that requires the user login using some kind of web form (think Starbucks or Wi-Fi at airports) then my app fails with an error 500.

I notice Safari can detect this and launches the authentication page for the user. Is there a standard I can use on to provide this experience, or at least show the user a message asking them to open safari and log in?

You can try with this version of reachability ...

It has following intresting methods that can get you started:

// WWAN may be available, but not active until a connection has been established.
// WiFi may require a connection for VPN on Demand.
-(BOOL)isConnectionRequired; // Identical DDG variant.
-(BOOL)connectionRequired; // Apple's routine.
// Dynamic, on demand connection?
-(BOOL)isConnectionOnDemand;
// Is user intervention required?
-(BOOL)isInterventionRequired;

The basic method is: try to download a file somewhere, that you know will never move, and whose contents you already know. Compare the downloaded content with the content that should be downloaded, and you'll know you're on a captive hotspot or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM