Skip to content

Commit

Permalink
Merge pull request #1259 from smartdevicelink/bugfix/issue_1258_locks…
Browse files Browse the repository at this point in the history
…creen_crash_2

Fix all crashes due to lockscreen being setup before app window
  • Loading branch information
joeljfischer authored May 13, 2019
2 parents 90b48be + 51e0813 commit 2318259
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions SmartDeviceLink/SDLScreenshotViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,36 @@ - (instancetype)init {
return self;
}

// HAX: https://github.com/smartdevicelink/sdl_ios/issues/1250
// HAX: https://github.com/smartdevicelink/sdl_ios/issues/1250
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
UIViewController *viewController = [self sdl_topMostControllerForWindow:[UIApplication sharedApplication].windows[0]];

if (viewController == self) {
@throw [NSException sdl_invalidLockscreenSetupException];
return UIInterfaceOrientationMaskAll;
} else if (viewController != nil) {
return viewController.supportedInterfaceOrientations;
}

return UIInterfaceOrientationMaskAll;
}

// HAX: https://github.com/smartdevicelink/sdl_ios/issues/1250
// HAX: https://github.com/smartdevicelink/sdl_ios/issues/1250
- (BOOL)shouldAutorotate {
UIViewController *viewController = [self sdl_topMostControllerForWindow:[UIApplication sharedApplication].windows[0]];

if (viewController != nil) {
if (viewController == self) {
return YES;
} else if (viewController != nil) {
return viewController.shouldAutorotate;
}

return super.shouldAutorotate;
return YES;
}

- (UIViewController *)sdl_topMostControllerForWindow:(UIWindow *)window {
UIViewController *topController = window.rootViewController;

while (topController.presentedViewController) {
while (topController.presentedViewController != nil) {
topController = topController.presentedViewController;
}

Expand Down

0 comments on commit 2318259

Please sign in to comment.