On the iPhone, if you are currently in a TCP connection with a remote peer using 3G. If the user moves to a place with Wifi connectivity, does the iPhone OS automatically modify your connection to go through WiFi instead (assuming remote peer is also accessible via Wifi)? I ask because the docs point out that WiFi is preferred over 3G d开发者_开发问答ue to lower power consumption.
Yes, it does, if it sees a Wifi network you have already connected on. But you can tell the iPhone to "forget" that Wifi connection, then it will kepp 3G even when entering a zone where thiw Wifi connection is available.
For example, as soon as I go back home, the iPhone (iOS 4) switches on my Wifi network. If I go out, it goes to 3G, and when I'm in a zone with a known connection (Orange Wifi), it switches to it.
The answer is no, there's nothing automatic here. If you connected on WWAN while there was no wifi connectivity, you'll stay on that WWAN connection, even when wifi becomes available. I tested this on iOS 4.2, and I don't believe there's anything different in iOS 5. I'd even argue that it couldn't realistically work any other way, period.
You can use the Reachability API to check if wifi is available and reconnect yourself.
精彩评论