Browse Source

Add public API to determine if FLEXNetworkObserver is enabled.

Also post a notification when the enabled state changes.
Ryan Olson 11 years ago
parent
commit
d74bc56487

+ 3 - 0
Classes/Network/PonyDebugger/FLEXNetworkObserver.h

@@ -12,6 +12,8 @@
 //  which Square, Inc. licenses this file to you.
 //
 
+extern NSString *const kFLEXNetworkObserverEnabledStateChangedNotification;
+
 @class FLEXNetworkRecorder;
 
 /// This class swizzles NSURLConnection and NSURLSession delegate methods to observe events in the URL loading system.
@@ -21,5 +23,6 @@
 /// Swizzling occurs when the observer is enabled for the first time.
 /// This reduces the impact of FLEX if network debugging is not desired.
 + (void)setEnabled:(BOOL)enabled;
++ (BOOL)isEnabled;
 
 @end

+ 14 - 0
Classes/Network/PonyDebugger/FLEXNetworkObserver.m

@@ -19,6 +19,7 @@
 #import <objc/message.h>
 #import <dispatch/queue.h>
 
+NSString *const kFLEXNetworkObserverEnabledStateChangedNotification = @"kFLEXNetworkObserverEnabledStateChangedNotification";
 
 @interface FLEXInternalRequestState : NSObject
 
@@ -85,6 +86,19 @@
     [[self sharedObserver] setEnabled:enabled];
 }
 
++ (BOOL)isEnabled
+{
+    return [[self sharedObserver] isEnabled];
+}
+
+- (void)setEnabled:(BOOL)enabled
+{
+    if (_enabled != enabled) {
+        _enabled = enabled;
+        [[NSNotificationCenter defaultCenter] postNotificationName:kFLEXNetworkObserverEnabledStateChangedNotification object:self];
+    }
+}
+
 #pragma mark - Statics
 
 + (instancetype)sharedObserver