Permalink
Browse files

Bug fix for issue #1 - Now supports universal apps that run on both i…

…OS 4 (with GCD) and prior OS versions (without GCD).
  • Loading branch information...
1 parent e0d0151 commit fc8705cb9378efbdf8160f9c8fdddf246d4127ad @robbiehanson robbiehanson committed Jul 1, 2010
View
@@ -79,26 +79,33 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
{
NSLogInfo(@"DDFileLogManagerDefault: Responding to configuration change: maximumNumberOfLogFiles");
- #if GCD_AVAILABLE
-
- dispatch_block_t block = ^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ if (IS_GCD_AVAILABLE)
+ {
+ #if GCD_MAYBE_AVAILABLE
- [self deleteOldLogFiles];
+ dispatch_block_t block = ^{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ [self deleteOldLogFiles];
+
+ [pool release];
+ };
- [pool release];
- };
-
- dispatch_async([DDLog loggingQueue], block);
-
- #else
-
- [self performSelector:@selector(deleteOldLogFiles)
- onThread:[DDLog loggingThread]
- withObject:nil
- waitUntilDone:NO];
-
- #endif
+ dispatch_async([DDLog loggingQueue], block);
+
+ #endif
+ }
+ else
+ {
+ #if GCD_MAYBE_UNAVAILABLE
+
+ [self performSelector:@selector(deleteOldLogFiles)
+ onThread:[DDLog loggingThread]
+ withObject:nil
+ waitUntilDone:NO];
+
+ #endif
+ }
}
}
@@ -497,50 +504,65 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
{
NSLogInfo(@"DDFileLogger: Responding to configuration change: maximumFileSize");
- #if GCD_AVAILABLE
-
- dispatch_block_t block = ^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ if (IS_GCD_AVAILABLE)
+ {
+ #if GCD_MAYBE_AVAILABLE
- [self maybeRollLogFileDueToSize];
+ dispatch_block_t block = ^{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ [self maybeRollLogFileDueToSize];
+
+ [pool release];
+ };
- [pool release];
- };
-
- dispatch_async([DDLog loggingQueue], block);
- #else
-
- [self performSelector:@selector(maybeRollLogFileDueToSize)
- onThread:[DDLog loggingThread]
- withObject:nil
- waitUntilDone:NO];
-
- #endif
+ dispatch_async([DDLog loggingQueue], block);
+
+ #endif
+ }
+ else
+ {
+ #if GCD_MAYBE_UNAVAILABLE
+
+ [self performSelector:@selector(maybeRollLogFileDueToSize)
+ onThread:[DDLog loggingThread]
+ withObject:nil
+ waitUntilDone:NO];
+
+ #endif
+ }
}
else if([keyPath isEqualToString:@"rollingFrequency"])
{
NSLogInfo(@"DDFileLogger: Responding to configuration change: rollingFrequency");
- #if GCD_AVAILABLE
-
- dispatch_block_t block = ^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ if (IS_GCD_AVAILABLE)
+ {
+ #if GCD_MAYBE_AVAILABLE
- [self maybeRollLogFileDueToAge:nil];
+ dispatch_block_t block = ^{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ [self maybeRollLogFileDueToAge:nil];
+
+ [pool release];
+ };
- [pool release];
- };
-
- dispatch_async([DDLog loggingQueue], block);
-
- #else
-
- [self performSelector:@selector(maybeRollLogFileDueToAge:)
- onThread:[DDLog loggingThread]
- withObject:nil
- waitUntilDone:NO];
-
- #endif
+ dispatch_async([DDLog loggingQueue], block);
+
+ #endif
+ }
+ else
+ {
+ #if GCD_MAYBE_UNAVAILABLE
+
+ [self performSelector:@selector(maybeRollLogFileDueToAge:)
+ onThread:[DDLog loggingThread]
+ withObject:nil
+ waitUntilDone:NO];
+
+ #endif
+ }
}
}
View
@@ -34,13 +34,86 @@
// Can we use Grand Central Dispatch?
+//
+// This question actually is actually composed of two parts:
+// 1. Is it available to the compiler?
+// 2. Is it available to the runtime?
+//
+// For example, if we are building a universal iPad/iPhone app,
+// our base SDK may be iOS 4, but our deployment target would be iOS 3.2.
+// In this case we can compile against the GCD libraries (which are available starting with iOS 4),
+// but we can only use them at runtime if running on iOS 4 or later.
+// If running on an iPad using iOS 3.2, we need to use runtime checks for backwards compatibility.
+//
+// The solution is to use a combination of compile-time and run-time macros.
+//
+// Note that when the minimum supported SDK supports GCD
+// the run-time checks will be compiled out during optimization.
+
+#if TARGET_OS_IPHONE
+
+ // Compiling for iPod/iPhone/iPad
+
+ #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000 // 4.0 supported
+
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000 // 4.0 supported and required
+
+ #define IS_GCD_AVAILABLE YES
+ #define GCD_MAYBE_AVAILABLE 1
+ #define GCD_MAYBE_UNAVAILABLE 0
+
+ #else // 4.0 supported but not required
+
+ #ifndef NSFoundationVersionNumber_iPhoneOS_4_0
+ #define NSFoundationVersionNumber_iPhoneOS_4_0 751.32
+ #endif
+
+ #define IS_GCD_AVAILABLE (NSFoundationVersionNumber >= NSFoundationVersionNumber_iPhoneOS_4_0)
+ #define GCD_MAYBE_AVAILABLE 1
+ #define GCD_MAYBE_UNAVAILABLE 1
+
+ #endif
+
+ #else // 4.0 not supported
+
+ #define IS_GCD_AVAILABLE NO
+ #define GCD_MAYBE_AVAILABLE 0
+ #define GCD_MAYBE_UNAVAILABLE 1
+
+ #endif
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 // Mac OS X 10.6
- #define GCD_AVAILABLE 1
-#elif __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000 // iPhone 4.0
- #define GCD_AVAILABLE 1
#else
- #define GCD_AVAILABLE 0
+
+ // Compiling for Mac OS X
+
+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 // 10.6 supported
+
+ #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 // 10.6 supported and required
+
+ #define IS_GCD_AVAILABLE YES
+ #define GCD_MAYBE_AVAILABLE 1
+ #define GCD_MAYBE_UNAVAILABLE 0
+
+ #else // 10.6 supported but not required
+
+ #ifndef NSFoundationVersionNumber10_6
+ #define NSFoundationVersionNumber10_6 751.00
+ #endif
+
+ #define IS_GCD_AVAILABLE (NSFoundationVersionNumber >= NSFoundationVersionNumber10_6)
+ #define GCD_MAYBE_AVAILABLE 1
+ #define GCD_MAYBE_UNAVAILABLE 1
+
+ #endif
+
+ #else // 10.6 not supported
+
+ #define IS_GCD_AVAILABLE NO
+ #define GCD_MAYBE_AVAILABLE 0
+ #define GCD_MAYBE_UNAVAILABLE 1
+
+ #endif
+
#endif
@class DDLogMessage;
@@ -146,7 +219,7 @@ NSString *ExtractFileNameWithoutExtension(const char *filePath, BOOL copy);
@interface DDLog : NSObject
-#if GCD_AVAILABLE
+#if GCD_MAYBE_AVAILABLE
/**
* Provides access to the underlying logging queue.
@@ -155,7 +228,9 @@ NSString *ExtractFileNameWithoutExtension(const char *filePath, BOOL copy);
+ (dispatch_queue_t)loggingQueue;
-#else
+#endif
+
+#if GCD_MAYBE_UNAVAILABLE
/**
* Provides access to the underlying logging thread.
@@ -252,7 +327,7 @@ NSString *ExtractFileNameWithoutExtension(const char *filePath, BOOL copy);
- (void)didAddLogger;
- (void)willRemoveLogger;
-#if GCD_AVAILABLE
+#if GCD_MAYBE_AVAILABLE
/**
* When Grand Central Dispatch is available
Oops, something went wrong.

0 comments on commit fc8705c

Please sign in to comment.