From 07a362b6a3f54d7a1c1e6aeda61fa643281a9d5e Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Tue, 9 Jan 2018 10:42:53 -0500 Subject: [PATCH] Fix #838 Lock screen presenter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * When app window isn’t in the expected place in the array, iterate through it instead --- SmartDeviceLink/SDLLockScreenPresenter.m | 34 +++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/SmartDeviceLink/SDLLockScreenPresenter.m b/SmartDeviceLink/SDLLockScreenPresenter.m index 263b097b0..f72d6d776 100644 --- a/SmartDeviceLink/SDLLockScreenPresenter.m +++ b/SmartDeviceLink/SDLLockScreenPresenter.m @@ -39,10 +39,22 @@ - (instancetype)init { - (void)present { dispatch_async(dispatch_get_main_queue(), ^{ + if (self.lockWindow.isKeyWindow) { + SDLLogW(@"Attempted to present lock window when it is already presented"); + return; + } + NSArray* windows = [[UIApplication sharedApplication] windows]; - UIWindow* appWindow = windows.firstObject; + UIWindow *appWindow = nil; + for (UIWindow *window in windows) { + if (window != self.lockWindow) { + appWindow = window; + break; + } + } - if (self.lockWindow.isKeyWindow || appWindow == self.lockWindow) { + if (appWindow == nil) { + SDLLogE(@"Unable to find the app's window"); return; } @@ -69,11 +81,20 @@ - (void)present { - (void)dismiss { dispatch_async(dispatch_get_main_queue(), ^{ - NSArray *windows = [[UIApplication sharedApplication] windows]; - UIWindow *appWindow = windows.firstObject; + NSArray* windows = [[UIApplication sharedApplication] windows]; + UIWindow *appWindow = nil; + for (UIWindow *window in windows) { + if (window != self.lockWindow) { + appWindow = window; + break; + } + } - if (appWindow.isKeyWindow || appWindow == self.lockWindow) { + if (appWindow == nil) { + SDLLogE(@"Unable to find the app's window"); return; + } else if (appWindow.isKeyWindow) { + SDLLogW(@"Attempted to dismiss lock screen, but it is already dismissed"); } // Let us know we are about to dismiss. @@ -105,7 +126,7 @@ - (BOOL)presented { isPresented = [self sdl_presented]; }); } - + return isPresented; } @@ -116,3 +137,4 @@ - (BOOL)sdl_presented { @end NS_ASSUME_NONNULL_END +