Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #838 Lock screen presenter #839

Merged
merged 1 commit into from
Jan 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions SmartDeviceLink/SDLLockScreenPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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.
Expand Down Expand Up @@ -105,7 +126,7 @@ - (BOOL)presented {
isPresented = [self sdl_presented];
});
}

return isPresented;
}

Expand All @@ -116,3 +137,4 @@ - (BOOL)sdl_presented {
@end

NS_ASSUME_NONNULL_END