Rework delivery of AFNetworkingOperationDidStartNotification and AFNetworkingOperationDidFinishNotification to avoid crashes when logging in response to notifications

This commit is contained in:
Blake Watters 2013-03-06 21:40:56 -05:00
Родитель 61188e2dad
Коммит db305db733
1 изменённых файлов: 15 добавлений и 19 удалений

Просмотреть файл

@ -339,20 +339,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
[self didChangeValueForKey:oldStateKey];
[self didChangeValueForKey:newStateKey];
[self.lock unlock];
dispatch_async(dispatch_get_main_queue(), ^{
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
switch (state) {
case AFOperationExecutingState:
[notificationCenter postNotificationName:AFNetworkingOperationDidStartNotification object:self];
break;
case AFOperationFinishedState:
[notificationCenter postNotificationName:AFNetworkingOperationDidFinishNotification object:self];
break;
default:
break;
}
});
}
- (NSString *)responseString {
@ -450,24 +436,34 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
- (void)operationDidStart {
[self.lock lock];
if ([self isCancelled]) {
[self finish];
} else {
if (! [self isCancelled]) {
self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
for (NSString *runLoopMode in self.runLoopModes) {
[self.connection scheduleInRunLoop:runLoop forMode:runLoopMode];
[self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode];
}
[self.connection start];
}
[self.lock unlock];
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidStartNotification object:self];
});
if ([self isCancelled]) {
[self finish];
}
}
- (void)finish {
self.state = AFOperationFinishedState;
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidFinishNotification object:self];
});
}
- (void)cancel {