From ea82228a24b8f5805ace28a49385ace3eb2162f9 Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Fri, 13 Mar 2020 14:47:56 -0400 Subject: Fix lock screen bug * Make sure `stop` completion handler is always called * Use strong / weak in all blocks --- SmartDeviceLink/SDLLockScreenPresenter.m | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/SmartDeviceLink/SDLLockScreenPresenter.m b/SmartDeviceLink/SDLLockScreenPresenter.m index 8e6c8b080..b891171b3 100644 --- a/SmartDeviceLink/SDLLockScreenPresenter.m +++ b/SmartDeviceLink/SDLLockScreenPresenter.m @@ -41,14 +41,20 @@ NS_ASSUME_NONNULL_BEGIN self.shouldShowLockScreen = NO; if (self.lockWindow == nil) { + if (completionHandler != nil) { + completionHandler(); + } return; } // Dismiss and destroy the lockscreen window + __weak typeof(self) weakSelf = self; [self sdl_dismissWithCompletionHandler:^(BOOL success) { + __strong typeof(weakSelf) strongSelf = weakSelf; + if (success) { - self.lockWindow = nil; - self.lockViewController = nil; + strongSelf.lockWindow = nil; + strongSelf.lockViewController = nil; } if (completionHandler != nil) { @@ -63,27 +69,30 @@ NS_ASSUME_NONNULL_BEGIN // Store the expected state of the lockscreen self.shouldShowLockScreen = show; + __weak typeof(self) weakSelf = self; if (show) { [self sdl_presentWithCompletionHandler:^{ - if (self.shouldShowLockScreen) { + __strong typeof(weakSelf) strongSelf = weakSelf; + if (strongSelf.shouldShowLockScreen) { if (completionHandler != nil) { completionHandler(); } return; } SDLLogV(@"The lockscreen has been presented but needs to be dismissed"); - [self sdl_dismissWithCompletionHandler:^(BOOL success) { + [strongSelf sdl_dismissWithCompletionHandler:^(BOOL success) { if (completionHandler != nil) { completionHandler(); } }]; }]; } else { [self sdl_dismissWithCompletionHandler:^(BOOL success) { - if (!self.shouldShowLockScreen) { + __strong typeof(weakSelf) strongSelf = weakSelf; + if (!strongSelf.shouldShowLockScreen) { if (completionHandler != nil) { completionHandler(); } return; } SDLLogV(@"The lockscreen has been dismissed but needs to be presented"); - [self sdl_presentWithCompletionHandler:completionHandler]; + [strongSelf sdl_presentWithCompletionHandler:completionHandler]; }]; } } -- cgit v1.2.1