diff --git a/Simperium/SPEnvironment.m b/Simperium/SPEnvironment.m index 0d2c51d8..a90496d6 100644 --- a/Simperium/SPEnvironment.m +++ b/Simperium/SPEnvironment.m @@ -30,7 +30,7 @@ #endif // TODO: Update this automatically via a script that looks at current git tag -NSString* const SPLibraryVersion = @"1.5.0"; +NSString* const SPLibraryVersion = @"1.6.0"; /// SSL Pinning /// diff --git a/Simperium/Simperium.m b/Simperium/Simperium.m index f619a1d6..372e5c05 100644 --- a/Simperium/Simperium.m +++ b/Simperium/Simperium.m @@ -837,7 +837,7 @@ - (void)authenticationDidFail { } // Delay it a touch to avoid issues with storyboard-driven UIs - [self performSelector:@selector(delayedOpenAuthViewController) withObject:nil afterDelay:0.1]; + [self scheduleOpenAuthViewController]; } - (BOOL)authenticateIfNecessary { @@ -850,6 +850,14 @@ - (BOOL)authenticateIfNecessary { return [self.authenticator authenticateIfNecessary]; } +- (void)scheduleOpenAuthViewController { + [self performSelector:@selector(delayedOpenAuthViewController) withObject:nil afterDelay:0.1]; +} + +- (void)unscheduleOpenAuthViewController { + [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(delayedOpenAuthViewController) object:nil]; +} + - (void)delayedOpenAuthViewController { [self openAuthViewControllerAnimated:YES]; } @@ -903,9 +911,15 @@ - (void)openAuthViewControllerAnimated:(BOOL)animated { } // Hide the main window and show the auth window instead - [self.window setIsVisible:NO]; - [[self.authenticationWindowController window] center]; - [[self.authenticationWindowController window] makeKeyAndOrderFront:self]; + [self.window setIsVisible:NO]; + + // Center the AuthWindow *only* when it wasn't previously onscreen (only after alloc!) + NSWindow *authWindow = self.authenticationWindowController.window; + if (!authWindow.isVisible) { + [authWindow center]; + } + + [authWindow makeKeyAndOrderFront:self]; #endif } @@ -921,6 +935,8 @@ - (void)closeAuthViewControllerAnimated:(BOOL)animated { [[self.authenticationWindowController window] close]; self.authenticationWindowController = nil; #endif + + [self unscheduleOpenAuthViewController]; }