Network error while switching from WiFi to 3G

2019-08-27 07:06发布

问题:

My iPhone app is web based.It works fine while running in WiFi and in 3G But the problem is when I run the app on WiFi and minimize it,and turn off the WiFi and switch to 3G-it shows no network.

In user's case-when they use the app under WiFi and goes out it failed to connect with 3G network.I am using apple's Reachability class to check the network connection Anybody please tell any solution

Do i code something to reconnect if the connection lost or switch from WiFi to 3G ?

回答1:

You can use connection:didFailWithError: and implement into your method to reconnect your user.

Like this

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    [self reconnect];
}

- (void)reconnect
{
   //reconnect your user
}

I hope it can help you ! ;)