Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // CRReachability.m
- // ChloeRoses
- //
- // Created by Emal Saifi [DAN-PARIS] on 13/08/13.
- // Copyright (c) 2013 Emal Saifi [DAN-PARIS]. All rights reserved.
- //
- #import "CRReachability.h"
- static CRReachability *sharedMyCRReachability= nil;
- @implementation CRReachability
- @synthesize reach = _reach;
- @synthesize isConnectionReachable = _isConnectionReachable;
- @synthesize delegate = _delegate;
- #pragma mark Singleton Methods
- + (id)sharedManager {
- @synchronized(self) {
- if(sharedMyCRReachability == nil)
- sharedMyCRReachability = [[super allocWithZone:NULL] init];
- }
- return sharedMyCRReachability;
- }
- + (id)allocWithZone:(NSZone *)zone {
- return [[self sharedManager] retain];
- }
- - (id)copyWithZone:(NSZone *)zone {
- return self;
- }
- - (id)retain {
- return self;
- }
- - (unsigned)retainCount {
- return UINT_MAX; //denotes an object that cannot be released
- }
- - (oneway void)release {
- // never release
- }
- - (id)autorelease {
- return self;
- }
- - (id)init {
- if (self = [super init]) {
- [self reachability];
- }
- return self;
- }
- -(void)reachability{
- self.reach = [Reachability reachabilityWithHostname:@"www.google.com"];
- self.reach.reachableBlock = ^(Reachability * reachability)
- {
- dispatch_async(dispatch_get_main_queue(), ^{
- NSLog(@"Block Says Reachable");
- self.isConnectionReachable = YES;
- if([self.delegate respondsToSelector:@selector(crReachability:getConnectionReachable:)])
- [self.delegate crReachability:self getConnectionReachable:self.isConnectionReachable];
- });
- };
- self.reach.unreachableBlock = ^(Reachability * reachability)
- {
- dispatch_async(dispatch_get_main_queue(), ^{
- NSLog(@"Block Says Unreachable");
- self.isConnectionReachable = NO;
- if([self.delegate respondsToSelector:@selector(crReachability:getConnectionReachable:)])
- [self.delegate crReachability:self getConnectionReachable:self.isConnectionReachable];
- });
- };
- }
- - (void)startReachability {
- NSLog(@"startReachability");
- [self.reach startNotifier];
- }
- - (void)stopReachability {
- if( [self.reach isReachable] == YES ) {
- NSLog(@"stopReachability");
- [self.reach stopNotifier];
- }
- }
- - (void)dealloc {
- // Should never be called, but just here for clarity really.
- [_reach release];
- [_delegate release];
- [super dealloc];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement