Skip to content

Commit f16f657

Browse files
committed
Merge pull request #83 from ParsePlatform/nlutsenko.networkIndicator
Add automatic management of Network Activity Indicator on iOS.
2 parents a08ca14 + d4dc9ec commit f16f657

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Parse/PFNetworkActivityIndicatorManager.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "PFNetworkActivityIndicatorManager.h"
1111

1212
#import "PFApplication.h"
13+
#import "PFCommandRunningConstants.h"
1314

1415
static NSTimeInterval const PFNetworkActivityIndicatorVisibilityDelay = 0.17;
1516

@@ -49,10 +50,20 @@ - (instancetype)init {
4950
_networkActivityAccessQueue = dispatch_queue_create("com.parse.networkActivityIndicatorManager",
5051
DISPATCH_QUEUE_SERIAL);
5152

53+
[[NSNotificationCenter defaultCenter] addObserver:self
54+
selector:@selector(_handleWillSendURLRequestNotification:)
55+
name:PFCommandRunnerWillSendURLRequestNotification
56+
object:nil];
57+
[[NSNotificationCenter defaultCenter] addObserver:self
58+
selector:@selector(_handleDidReceiveURLResponseNotification:)
59+
name:PFCommandRunnerDidReceiveURLResponseNotification
60+
object:nil];
61+
5262
return self;
5363
}
5464

5565
- (void)dealloc {
66+
[[NSNotificationCenter defaultCenter] removeObserver:self];
5667
[_activityIndicatorVisibilityTimer invalidate];
5768
}
5869

@@ -137,4 +148,16 @@ - (void)_updateNetworkActivityIndicatorVisibility {
137148
}
138149
}
139150

151+
///--------------------------------------
152+
#pragma mark - Command Running
153+
///--------------------------------------
154+
155+
- (void)_handleWillSendURLRequestNotification:(NSNotification *)notification {
156+
[self incrementActivityCount];
157+
}
158+
159+
- (void)_handleDidReceiveURLResponseNotification:(NSNotification *)notification {
160+
[self decrementActivityCount];
161+
}
162+
140163
@end

0 commit comments

Comments
 (0)