|
48 | 48 | static NSInteger ApptentiveInternalInconsistency = -201;
|
49 | 49 | static NSInteger ApptentiveAlreadyLoggedInErrorCode = -202;
|
50 | 50 | static NSInteger ApptentiveInBackgroundErrorCode = -203;
|
| 51 | +static NSInteger ApptentiveLoginRequestInProcessErrorCode = -204; |
51 | 52 |
|
52 | 53 | NSString *const ApptentiveConversationStateDidChangeNotification = @"ApptentiveConversationStateDidChangeNotification";
|
53 | 54 | NSString *const ApptentiveConversationStateDidChangeNotificationKeyConversation = @"conversation";
|
@@ -295,6 +296,12 @@ - (void)createMessageManagerForConversation:(ApptentiveConversation *)conversati
|
295 | 296 | - (void)endActiveConversation {
|
296 | 297 | ApptentiveAssertOperationQueue(self.operationQueue);
|
297 | 298 |
|
| 299 | + if (self.loginRequestOperation != nil) { |
| 300 | + ApptentiveLogInfo(ApptentiveLogTagConversation, @"Cancelling login request due to logout"); |
| 301 | + [self.loginRequestOperation cancel]; |
| 302 | + self.loginRequestOperation = nil; |
| 303 | + } |
| 304 | + |
298 | 305 | if (self.activeConversation != nil) {
|
299 | 306 | ApptentiveMutableConversation *conversation = [self.activeConversation mutableCopy];
|
300 | 307 |
|
@@ -470,13 +477,18 @@ - (BOOL)saveMetadata {
|
470 | 477 | - (void)logInWithToken:(NSString *)token completion:(void (^)(BOOL, NSError *_Nonnull))completion {
|
471 | 478 | ApptentiveAssertOperationQueue(self.operationQueue);
|
472 | 479 |
|
473 |
| - self.loginCompletionBlock = [completion copy]; |
474 |
| - |
475 |
| - [self requestLoggedInConversationWithToken:token]; |
| 480 | + [self requestLoggedInConversationWithToken:token completion:completion]; |
476 | 481 | }
|
477 | 482 |
|
478 |
| -- (void)requestLoggedInConversationWithToken:(NSString *)token { |
| 483 | +- (void)requestLoggedInConversationWithToken:(NSString *)token completion:(void (^)(BOOL, NSError *_Nonnull))completion { |
479 | 484 | [self.operationQueue dispatchAsync:^{
|
| 485 | + self.loginCompletionBlock = [completion copy]; |
| 486 | + |
| 487 | + if (self.loginRequestOperation != nil) { |
| 488 | + [self failLoginWithErrorCode:ApptentiveLoginRequestInProcessErrorCode failureReason:@"Login request already in process."]; |
| 489 | + return; |
| 490 | + } |
| 491 | + |
480 | 492 | if (!Apptentive.shared.backend.foreground) {
|
481 | 493 | [self failLoginWithErrorCode:ApptentiveInBackgroundErrorCode failureReason:@"App is in background state"];
|
482 | 494 | return;
|
@@ -583,8 +595,14 @@ - (void)failLoginWithErrorCode:(NSInteger)errorCode failureReason:(NSString *)fo
|
583 | 595 | }
|
584 | 596 |
|
585 | 597 | - (void)completeLoginSuccess:(BOOL)success error:(nullable NSError *)error {
|
586 |
| - self.loginCompletionBlock(success, error); |
587 |
| - self.loginCompletionBlock = nil; |
| 598 | + ApptentiveAssertNotNil(self.loginCompletionBlock, @"Login completion block was nil"); |
| 599 | + |
| 600 | + if (_loginCompletionBlock != nil) { |
| 601 | + self.loginCompletionBlock(success, error); |
| 602 | + self.loginCompletionBlock = nil; |
| 603 | + } else { |
| 604 | + ApptentiveLogError(ApptentiveLogTagConversation, @"Unexpectedly found nil login completion block"); |
| 605 | + } |
588 | 606 | }
|
589 | 607 |
|
590 | 608 | #pragma mark - ApptentiveConversationDelegate
|
|
0 commit comments