diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2018-01-09 10:42:53 -0500 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2018-01-09 10:42:53 -0500 |
commit | 07a362b6a3f54d7a1c1e6aeda61fa643281a9d5e (patch) | |
tree | 2bd2c78469e563e01c992df86de84ceb74f16cfb | |
parent | 273698b7deb9d20719007809a29b37f787384a47 (diff) | |
download | sdl_ios-07a362b6a3f54d7a1c1e6aeda61fa643281a9d5e.tar.gz |
Fix #838 Lock screen presenter
* When app window isn’t in the expected place in the array, iterate through it instead
-rw-r--r-- | SmartDeviceLink/SDLLockScreenPresenter.m | 34 |
1 files 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 @@ NS_ASSUME_NONNULL_BEGIN - (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 @@ NS_ASSUME_NONNULL_BEGIN - (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 @@ NS_ASSUME_NONNULL_BEGIN isPresented = [self sdl_presented]; }); } - + return isPresented; } @@ -116,3 +137,4 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END + |