Skip to content

Commit 48ca084

Browse files
committed
Merge pull request AFNetworking#842 from 0xced/no-nil-network-activity
Update network activity indicator only if requests have a non nil URL
2 parents 27c357a + 9c35300 commit 48ca084

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

AFNetworking/AFNetworkActivityIndicatorManager.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ - (id)init {
6262
return nil;
6363
}
6464

65-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(incrementActivityCount) name:AFNetworkingOperationDidStartNotification object:nil];
66-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(decrementActivityCount) name:AFNetworkingOperationDidFinishNotification object:nil];
65+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkingOperationDidStart:) name:AFNetworkingOperationDidStartNotification object:nil];
66+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkingOperationDidFinish:) name:AFNetworkingOperationDidFinishNotification object:nil];
6767

6868
return self;
6969
}
@@ -126,6 +126,20 @@ - (void)decrementActivityCount {
126126
[self updateNetworkActivityIndicatorVisibilityDelayed];
127127
}
128128

129+
- (void)networkingOperationDidStart:(NSNotification *)notification {
130+
AFURLConnectionOperation *connectionOperation = [notification object];
131+
if (connectionOperation.request.URL) {
132+
[self incrementActivityCount];
133+
}
134+
}
135+
136+
- (void)networkingOperationDidFinish:(NSNotification *)notification {
137+
AFURLConnectionOperation *connectionOperation = [notification object];
138+
if (connectionOperation.request.URL) {
139+
[self decrementActivityCount];
140+
}
141+
}
142+
129143
@end
130144

131145
#endif

0 commit comments

Comments
 (0)