objective-cmacoscocoacorewlan

Network operation fails after switching the network


I am using Core WLAN framework to switch between WiFi networks. I am facing a problem that after I switch from WiFi network 1 to WiFi 2, I have to wait for 10 seconds before I instantiate any network activity. Though the WiFi symbol shows the correct value before I put a wait for 10 seconds. Anyone has any clue as why this happens? And any remedy for this.

Core WLAN Framework link:

http://developer.apple.com/library/mac/#documentation/Networking/Reference/CoreWLANFrameworkRef/_index.html


Solution

  • There is no way to predict how long it will take to have a given network assign your system an IP address, for DNS resolution to begin to work, etc etc. Instead of waiting for a specific timeout, use the SCNetworkReachability API to take action when the system can access a given host or service.

    Sample code: http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html