Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for slow internet connection iOS

Tags:

ios

I have added Reachability classes provided by apple and it is working fine for checking internet connection. MY app is displaying message if internet goes off.

But if internet is very slow it just keep loading.......

I am using wi-fi and I face this problem when there is only a dot visible in iPhone notification bar for wifi signal.

So I want to know how can I check for slow internet connection.

like image 956
CRDave Avatar asked Dec 17 '12 06:12

CRDave


1 Answers

You can send a request to your server and given that it's about 5-10 KB of data you expect to be returned, then create a timer callback that is scheduled for say 20 seconds.

If you don't get a response within 20 seconds, then let's consider that a slow connection.

Example:

// make POST request to server, the POST request should have a callback method assigned
[self testSpeed];

// schedule a method to be called after 20 seconds
myTimer = [NSTimer scheduledTimerWithInterval:20.0 selector:@selector(stopSpeedTest) .... ];

// your POST request callback method
-(void)speedTestCallback
{
    [myTimer invalidate];
    myTimer = nil;

    [self alertGoodSpeed];
}

// your stopSpeedTest method to identify app didn't receive response within 20 seconds
-(void)stopSpeedTest
{
    [self alertTooSlow];
}

I think that's what H2CO3 was trying to ask:

"How many bytes per second do you consider slow?"

You need to decided on long you think the user is willing to wait for the amount of data expected to be returned.

If you're telling the user you're downloading 50 MB of data, then yes, getting them all back in 20 second is fast.

However, if you're expecting only 5-10 KB of data and it's taking longer than 10 seconds, let alone 20 seconds, then connection is very slow.

like image 142
Zhang Avatar answered Oct 19 '22 10:10

Zhang