Rework delivery of AFNetworkingOperationDidStartNotification and AFNetworkingOperationDidFinishNotification to avoid crashes when logging in response to notifications
This commit is contained in:
parent
61188e2dad
commit
db305db733
1 changed files with 15 additions and 19 deletions
|
|
@ -339,20 +339,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
[self didChangeValueForKey:oldStateKey];
|
[self didChangeValueForKey:oldStateKey];
|
||||||
[self didChangeValueForKey:newStateKey];
|
[self didChangeValueForKey:newStateKey];
|
||||||
[self.lock unlock];
|
[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 {
|
- (NSString *)responseString {
|
||||||
|
|
@ -450,9 +436,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
|
|
||||||
- (void)operationDidStart {
|
- (void)operationDidStart {
|
||||||
[self.lock lock];
|
[self.lock lock];
|
||||||
if ([self isCancelled]) {
|
if (! [self isCancelled]) {
|
||||||
[self finish];
|
|
||||||
} else {
|
|
||||||
self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO];
|
self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO];
|
||||||
|
|
||||||
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
|
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
|
||||||
|
|
@ -464,10 +448,22 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
[self.connection start];
|
[self.connection start];
|
||||||
}
|
}
|
||||||
[self.lock unlock];
|
[self.lock unlock];
|
||||||
|
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidStartNotification object:self];
|
||||||
|
});
|
||||||
|
|
||||||
|
if ([self isCancelled]) {
|
||||||
|
[self finish];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)finish {
|
- (void)finish {
|
||||||
self.state = AFOperationFinishedState;
|
self.state = AFOperationFinishedState;
|
||||||
|
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidFinishNotification object:self];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cancel {
|
- (void)cancel {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue