0

Here is my code to check whether internet connection is available or not for application.

-(BOOL)isReachable{
Reachability *r = [Reachability reachabilityWithHostName:@"www.apple.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
NSLog(@"internet status------%u",ReachableViaWiFi);
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
    NSLog(@"no net");
    //do something for no net connection
    return NO;

}
return YES;}

Above code works properly.When wifi is enabled and request send to cloudkit,data appears fast.but when cellular data is enable and request send to cloudkit,it took so much time to load data.So I want to check is there any way to check internet speed before sending request to cloudkit,so that I can inform my user that "it will take time to load data because internet speed is slow."

rmaddy
  • 314,917
  • 42
  • 532
  • 579
bittu
  • 683
  • 7
  • 24
  • There's really no perfect way. Some people's Wifi is worse than their cellular connection, especially if they have LTE. You could try and measure it yourself, but that's generally a waste of time. The best option is probably to just have some kind of progress indicator. People usually know when they're on a slow connection. – Avi Nov 30 '15 at 10:16
  • A note with respect to checking reachability: Do not use the answer from reachability to determine whether to send the request. It should only be used to determine why a request may have failed. Apple's documentation is clear on this -- lack of reachability, as determined by this API, does not always mean a lack of reachability to the particular service you are trying to reach. – Avi Nov 30 '15 at 10:18
  • @Avi: If connection is too slow and request is sent to cloudkit,it will take too much time to load data.At that time progress indicator not work properly.I want to show message to user that request is already sent but network connection is too slow,so please wait. – bittu Dec 01 '15 at 07:21
  • Use the `- [UIApplication setNetworkActivityIndicatorVisible:]` to show that there is activity. If the user really has to wait before doing anything, use something like `MBProgressHud`. – Avi Dec 01 '15 at 07:54
  • Possible duplicate of [1. Determine the speed on internet programmatically](http://stackoverflow.com/questions/9496058/determine-the-speed-on-internet-programmatically), [2. iOS NSUrlConnection check upload speed](http://stackoverflow.com/questions/22142909/ios-nsurlconnection-check-upload-speed), or [3. Calculating Connection/Download Speed](http://stackoverflow.com/questions/370641/calculating-connection-download-speed). refer this posts you might find solution. – Dipen Panchasara Dec 03 '15 at 06:04

0 Answers0