Permalink
Browse files

Added support for strongly retained queues

Also removed superfluous NSLogging
  • Loading branch information...
1 parent de7ed58 commit 83a5c5d7316f6c222565d61714f9247ada11a324 Tony Million committed Jul 23, 2012
Showing with 41 additions and 13 deletions.
  1. +27 −0 Reachability.h
  2. +14 −13 Reachability.m
View
@@ -35,6 +35,33 @@
#import <ifaddrs.h>
#import <netdb.h>
+/**
+ * Does ARC support support GCD objects?
+ * It does if the minimum deployment target is iOS 6+ or Mac OS X 8+
+ **/
+#if TARGET_OS_IPHONE
+
+// Compiling for iOS
+
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
+#define NEEDS_DISPATCH_RETAIN_RELEASE 0
+#else // iOS 5.X or earlier
+#define NEEDS_DISPATCH_RETAIN_RELEASE 1
+#endif
+
+#else
+
+// Compiling for Mac OS X
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
+#define NEEDS_DISPATCH_RETAIN_RELEASE 0
+#else
+#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
+#endif
+
+#endif
+
+
extern NSString *const kReachabilityChangedNotification;
typedef enum
View
@@ -33,7 +33,15 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
@interface Reachability ()
@property (nonatomic, assign) SCNetworkReachabilityRef reachabilityRef;
+
+
+#if NEEDS_DISPATCH_RETAIN_RELEASE
@property (nonatomic, assign) dispatch_queue_t reachabilitySerialQueue;
+#else
+@property (nonatomic, strong) dispatch_queue_t reachabilitySerialQueue;
+#endif
+
+
@property (nonatomic, strong) id reachabilityObject;
-(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags;
@@ -168,9 +176,6 @@ -(void)dealloc
CFRelease(self.reachabilityRef);
self.reachabilityRef = nil;
}
-#ifdef DEBUG
- NSLog(@"Reachability: dealloc");
-#endif
#if !(__has_feature(objc_arc))
[super dealloc];
@@ -216,7 +221,9 @@ -(BOOL)startNotifier
//clear out the dispatch queue
if(self.reachabilitySerialQueue)
{
+#ifdef NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(self.reachabilitySerialQueue);
+#endif
self.reachabilitySerialQueue = nil;
}
@@ -240,7 +247,9 @@ -(BOOL)startNotifier
// then clear out the dispatch queue
if(self.reachabilitySerialQueue)
{
+#ifdef NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(self.reachabilitySerialQueue);
+#endif
self.reachabilitySerialQueue = nil;
}
@@ -262,7 +271,9 @@ -(void)stopNotifier
if(self.reachabilitySerialQueue)
{
+#ifdef NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(self.reachabilitySerialQueue);
+#endif
self.reachabilitySerialQueue = nil;
}
@@ -466,27 +477,17 @@ -(NSString*)currentReachabilityFlags
-(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags
{
-#ifdef DEBUG
- NSLog(@"Reachability: %@", reachabilityFlags(flags));
-#endif
-
if([self isReachableWithFlags:flags])
{
if(self.reachableBlock)
{
-#ifdef DEBUG
- NSLog(@"Reachability: blocks are not called on the main thread.\n Use dispatch_async(dispatch_get_main_queue(), ^{}); to update your UI!");
-#endif
self.reachableBlock(self);
}
}
else
{
if(self.unreachableBlock)
{
-#ifdef DEBUG
- NSLog(@"Reachability: blocks are not called on the main thread.\n Use dispatch_async(dispatch_get_main_queue(), ^{}); to update your UI!");
-#endif
self.unreachableBlock(self);
}
}

0 comments on commit 83a5c5d

Please sign in to comment.