Giter Site home page Giter Site logo

Comments (7)

pburleson avatar pburleson commented on May 18, 2024

I would move this check out of applicationDidFinishLaunchingWithOptions because it can take more than 10 seconds. You should schedule things to start happening in applicationDidFinishLaunchingWithOptions and get out of that method as fast as you can.

For instance, you could dispatch_async [reachHost startNotifier] and return from applicationDidFinishLaunchingWithOptions.

from reachability.

AmirShaikh avatar AmirShaikh commented on May 18, 2024

Thanks pburleson
I did try dispatch_async [reachHost startNotifier] but this didn't seem to make any difference to the reachable = [reachHost isReachable]; call which I can see it hanging on for a while before returning,

Should I be doing this somewhere else?

from reachability.

tonymillion avatar tonymillion commented on May 18, 2024

yes, unfortunately under poor network connectivity Reachability can hang in certain situations.

if you try something like:

reachable = NO;
reachHost = [Reachability reachabilityWithHostname:@"www.google.com"];

    reachHost.reachableBlock = ^(Reachability * reachability)
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            reachable = YES;
        });
    };

    reachHost.unreachableBlock = ^(Reachability * reachability)
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            reachable = NO;
        });
    };

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
   reachable = [reachHost isReachable];
   [reachHost startNotifier];
}

Then the initial detection will happen on a background thread, then the notifier will start up. Notice I put both the initial detection and the startNotifier in the async call.

from reachability.

pburleson avatar pburleson commented on May 18, 2024

I'm trying to remember if Reachability has to be run on the main thread, but if it doesn't you should use the global queue instead of the main queue, as that continues to hang the main thread and will get you watchdog killed.

from reachability.

tonymillion avatar tonymillion commented on May 18, 2024

In addition, I'm curious why you need to run the initial isReachable?

Generally its better to try any network operations you were going to do, and catch them if they fail, queue them to be retried later, then when Reachability notifies you you have connectivity replay the queued operations.

from reachability.

soleares avatar soleares commented on May 18, 2024

isReachable shouldn't be called on app startup (on the main thread). Use the notification or blocks instead to update the reachability status. isReachable will block in low network situations which can result in the watchdog killing your app if it hangs for more than 20s. This will happen with Apple's reachability code too. I think it may talk about this in the readme or header in Apple's example.

from reachability.

AmirShaikh avatar AmirShaikh commented on May 18, 2024

I moved the isReachable check to a block and this works a lot better,

Tony, I agree it would be better not to call the initial isReachable but I'm making a data call to check for updates for my app as part of the launch, so i need to check for a connection.

Thanks for your replies all, will close if no further comments..

from reachability.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.