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 +