Skip to content

Instantly share code, notes, and snippets.

@gliubc
Last active July 22, 2019 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gliubc/1154563a5d49a84bcbe42b7a40e8407e to your computer and use it in GitHub Desktop.
Save gliubc/1154563a5d49a84bcbe42b7a40e8407e to your computer and use it in GitHub Desktop.
#import <Reachability.h>
@property (strong, nonatomic) Reachability *internetReachableFoo;
// Checks if we have an internet connection or not
- (void)testInternetConnection
{
self.internetReachableFoo = [Reachability reachabilityWithHostname:@"www.bing.com"];
// Internet is reachable
@weakify(self);
self.internetReachableFoo.reachableBlock = ^(Reachability*reach)
{
// Update the UI on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
@strongify(self);
[self loadRequest];
NSLog(@"Yayyy, we have the interwebs!");
});
};
// Internet is not reachable
self.internetReachableFoo.unreachableBlock = ^(Reachability*reach)
{
// Update the UI on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Someone broke the internet :(");
});
};
[self.internetReachableFoo startNotifier];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment