ios - How do I use Reachability to check if there's an internet connection, and if not, do something. (Basically use as a boolean.) -


i've read on code on reachability's page, i'm unclear how i'd use in if statement type scenario.

for example, user taps refresh button, firing refresh method (go figure, eh?) , if there internet connection, want refresh of data occur, if not, want send notification of no internet.

how achieve reachability?

would use code following have variable set value in each block depending on result, , @ after. seems less elegant, if it's way, it.

// allocate reachability object reachability* reach = [reachability reachabilitywithhostname:@"www.google.com"];  // set blocks  reach.reachableblock = ^(reachability*reach) {     nslog(@"reachable!"); };  reach.unreachableblock = ^(reachability*reach) {     nslog(@"unreachable!"); };  // start notifier cause reachability object retain itself! [reach startnotifier]; 

my app did - send message in block self on main thread - hostchanged:(bool)state. self class can maintain public ivar of state, or , notification other objects can listen for.

my app had function in app delegate easy other objects it.

note takes ios tens of seconds determine state, code launched assumption of up.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -