summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2019-11-08 13:38:24 -0500
committerJoel Fischer <joeljfischer@gmail.com>2019-11-08 13:38:24 -0500
commita9bea6f6554cc5e3d8a73d28870f8ae783d02700 (patch)
treefaff1b5f6796988d5b501d4b87e17ee2d6551c61
parent8ee188990f23421d76437194dde386a14a2f5986 (diff)
downloadsdl_ios-a9bea6f6554cc5e3d8a73d28870f8ae783d02700.tar.gz
Create a separate lockscreen code path for iOS 13-based scene APIs
-rw-r--r--Example Apps/Example Swift/AppDelegate.swift22
-rw-r--r--Example Apps/Example Swift/SceneDelegate.swift48
-rw-r--r--Example Apps/Example Swift/SmartDeviceLink-Example-Swift-Info.plist19
-rw-r--r--SmartDeviceLink-iOS.xcodeproj/project.pbxproj8
-rw-r--r--SmartDeviceLink/SDLLockScreenPresenter.m208
-rwxr-xr-xSmartDeviceLink/SDLScreenshotViewController.m12
6 files changed, 247 insertions, 70 deletions
diff --git a/Example Apps/Example Swift/AppDelegate.swift b/Example Apps/Example Swift/AppDelegate.swift
index d602970c7..826537cb0 100644
--- a/Example Apps/Example Swift/AppDelegate.swift
+++ b/Example Apps/Example Swift/AppDelegate.swift
@@ -20,25 +20,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}
- func applicationWillResignActive(_ application: UIApplication) {
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
- }
-
- func applicationDidEnterBackground(_ application: UIApplication) {
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- }
-
- func applicationWillEnterForeground(_ application: UIApplication) {
- // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
- }
-
- func applicationDidBecomeActive(_ application: UIApplication) {
- // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
- }
-
- func applicationWillTerminate(_ application: UIApplication) {
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+ func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
+ return UISceneConfiguration(name: "Default", sessionRole: connectingSceneSession.role)
}
}
diff --git a/Example Apps/Example Swift/SceneDelegate.swift b/Example Apps/Example Swift/SceneDelegate.swift
new file mode 100644
index 000000000..c06c1dec6
--- /dev/null
+++ b/Example Apps/Example Swift/SceneDelegate.swift
@@ -0,0 +1,48 @@
+//
+// SceneDelegate.swift
+// SmartDeviceLink-Example-Swift
+//
+// Created by Joel Fischer on 11/6/19.
+// Copyright © 2019 smartdevicelink. All rights reserved.
+//
+
+import UIKit
+
+class SceneDelegate: UIResponder, UIWindowSceneDelegate {
+ var window: UIWindow?
+
+ func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
+ // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
+ // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
+ // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
+ guard let _ = (scene as? UIWindowScene) else { return }
+ }
+
+ func sceneDidDisconnect(_ scene: UIScene) {
+ // Called as the scene is being released by the system.
+ // This occurs shortly after the scene enters the background, or when its session is discarded.
+ // Release any resources associated with this scene that can be re-created the next time the scene connects.
+ // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
+ }
+
+ func sceneDidBecomeActive(_ scene: UIScene) {
+ // Called when the scene has moved from an inactive state to an active state.
+ // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
+ }
+
+ func sceneWillResignActive(_ scene: UIScene) {
+ // Called when the scene will move from an active state to an inactive state.
+ // This may occur due to temporary interruptions (ex. an incoming phone call).
+ }
+
+ func sceneWillEnterForeground(_ scene: UIScene) {
+ // Called as the scene transitions from the background to the foreground.
+ // Use this method to undo the changes made on entering the background.
+ }
+
+ func sceneDidEnterBackground(_ scene: UIScene) {
+ // Called as the scene transitions from the foreground to the background.
+ // Use this method to save data, release shared resources, and store enough scene-specific state information
+ // to restore the scene back to its current state.
+ }
+}
diff --git a/Example Apps/Example Swift/SmartDeviceLink-Example-Swift-Info.plist b/Example Apps/Example Swift/SmartDeviceLink-Example-Swift-Info.plist
index 9b5e3074e..5749315c6 100644
--- a/Example Apps/Example Swift/SmartDeviceLink-Example-Swift-Info.plist
+++ b/Example Apps/Example Swift/SmartDeviceLink-Example-Swift-Info.plist
@@ -73,6 +73,25 @@
<string>com.ford.sync.prot0</string>
<string>com.smartdevicelink.multisession</string>
</array>
+ <key>UIApplicationSceneManifest</key>
+ <dict>
+ <key>UIApplicationSupportsMultipleScenes</key>
+ <true/>
+ <key>UISceneConfigurations</key>
+ <dict>
+ <key>UIWindowSceneSessionRoleApplication</key>
+ <array>
+ <dict>
+ <key>UISceneDelegateClassName</key>
+ <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
+ <key>UISceneConfigurationName</key>
+ <string>Default</string>
+ <key>UISceneStoryboardFile</key>
+ <string>Main</string>
+ </dict>
+ </array>
+ </dict>
+ </dict>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
index 249491f82..900fce652 100644
--- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
+++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
@@ -1217,6 +1217,7 @@
5DBF0D5E1F3A68C0008AF2C9 /* SDLControlFramePayloadVideoStartServiceSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DBF0D5D1F3A68C0008AF2C9 /* SDLControlFramePayloadVideoStartServiceSpec.m */; };
5DBF0D601F3B3DB4008AF2C9 /* SDLControlFrameVideoStartServiceAckSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DBF0D5F1F3B3DB4008AF2C9 /* SDLControlFrameVideoStartServiceAckSpec.m */; };
5DC09EDA1F2F7FEC00F4AB1D /* SDLControlFramePayloadNakSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DC09ED91F2F7FEC00F4AB1D /* SDLControlFramePayloadNakSpec.m */; };
+ 5DC49BDD237314B500B2B8F2 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DC49BDC237314B500B2B8F2 /* SceneDelegate.swift */; };
5DC978261B7A38640012C2F1 /* SDLGlobalsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DC978251B7A38640012C2F1 /* SDLGlobalsSpec.m */; };
5DCC458D221C9F6600036C2F /* SDLVersionSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DCC458C221C9F6600036C2F /* SDLVersionSpec.m */; };
5DCD7AE01FCCA8D200A0FC7F /* SDLCarWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DCD7ADC1FCCA8D100A0FC7F /* SDLCarWindow.h */; };
@@ -2964,6 +2965,7 @@
5DBF0D5D1F3A68C0008AF2C9 /* SDLControlFramePayloadVideoStartServiceSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLControlFramePayloadVideoStartServiceSpec.m; path = ControlFramePayloadSpecs/SDLControlFramePayloadVideoStartServiceSpec.m; sourceTree = "<group>"; };
5DBF0D5F1F3B3DB4008AF2C9 /* SDLControlFrameVideoStartServiceAckSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLControlFrameVideoStartServiceAckSpec.m; path = ControlFramePayloadSpecs/SDLControlFrameVideoStartServiceAckSpec.m; sourceTree = "<group>"; };
5DC09ED91F2F7FEC00F4AB1D /* SDLControlFramePayloadNakSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLControlFramePayloadNakSpec.m; path = ControlFramePayloadSpecs/SDLControlFramePayloadNakSpec.m; sourceTree = "<group>"; };
+ 5DC49BDC237314B500B2B8F2 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SceneDelegate.swift; path = "Example Apps/Example Swift/SceneDelegate.swift"; sourceTree = SOURCE_ROOT; };
5DC978251B7A38640012C2F1 /* SDLGlobalsSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLGlobalsSpec.m; path = UtilitiesSpecs/SDLGlobalsSpec.m; sourceTree = "<group>"; };
5DCA93821EE0844D0015768E /* SmartDeviceLink.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; path = SmartDeviceLink.podspec; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
5DCC458C221C9F6600036C2F /* SDLVersionSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDLVersionSpec.m; path = DevAPISpecs/SDLVersionSpec.m; sourceTree = "<group>"; };
@@ -6251,6 +6253,7 @@
5D1FF2F92130480C000EB9B4 /* SmartDeviceLink-Example-Swift-Info.plist */,
5D1FF2F7213047C1000EB9B4 /* AppDelegate.swift */,
5D1FF2F6213047C1000EB9B4 /* SmartDeviceLink-Example-Swift-Bridging-Header.h */,
+ 5DC49BDC237314B500B2B8F2 /* SceneDelegate.swift */,
);
name = "Supporting Files";
sourceTree = "<group>";
@@ -8350,6 +8353,7 @@
5D1FF2EC2130479C000EB9B4 /* ConnectionTCPTableViewController.swift in Sources */,
5D1FF2C4213045EB000EB9B4 /* AppConstants.m in Sources */,
5D1FF2DA21304746000EB9B4 /* ButtonManager.swift in Sources */,
+ 5DC49BDD237314B500B2B8F2 /* SceneDelegate.swift in Sources */,
5D1FF2DC21304746000EB9B4 /* AlertManager.swift in Sources */,
5D1FF2EB2130479C000EB9B4 /* ConnectionContainerViewController.swift in Sources */,
5D1FF2E021304746000EB9B4 /* MenuManager.swift in Sources */,
@@ -8761,7 +8765,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
DEVELOPMENT_TEAM = NCVC2MHU7M;
INFOPLIST_FILE = "$(SRCROOT)/Example Apps/Example Swift/SmartDeviceLink-Example-Swift-Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 6.4.0;
PRODUCT_BUNDLE_IDENTIFIER = com.smartdevicelink.SDLTestApp;
@@ -8781,7 +8785,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
DEVELOPMENT_TEAM = NCVC2MHU7M;
INFOPLIST_FILE = "$(SRCROOT)/Example Apps/Example Swift/SmartDeviceLink-Example-Swift-Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 6.4.0;
PRODUCT_BUNDLE_IDENTIFIER = com.smartdevicelink.SDLTestApp;
diff --git a/SmartDeviceLink/SDLLockScreenPresenter.m b/SmartDeviceLink/SDLLockScreenPresenter.m
index 3162f8cc9..0415e1c2a 100644
--- a/SmartDeviceLink/SDLLockScreenPresenter.m
+++ b/SmartDeviceLink/SDLLockScreenPresenter.m
@@ -25,29 +25,84 @@ NS_ASSUME_NONNULL_BEGIN
@implementation SDLLockScreenPresenter
+#pragma mark - Lifecycle
+
- (instancetype)init {
self = [super init];
if (!self) { return nil; }
CGRect screenFrame = [[UIScreen mainScreen] bounds];
_lockWindow = [[UIWindow alloc] initWithFrame:screenFrame];
+ _lockWindow.backgroundColor = [UIColor clearColor];
_screenshotViewController = [[SDLScreenshotViewController alloc] init];
_lockWindow.rootViewController = _screenshotViewController;
return self;
}
+#pragma mark - Present Lock Window
+
- (void)present {
dispatch_async(dispatch_get_main_queue(), ^{
- if (self.lockWindow.isKeyWindow) {
- SDLLogW(@"Attempted to present lock window when it is already presented");
- return;
+ if (@available(iOS 13.0, *)) {
+ [self sdl_presentIOS13];
+ } else {
+ [self sdl_presentIOS12];
+ }
+ });
+}
+
+- (void)sdl_presentIOS12 {
+ if (self.lockWindow.isKeyWindow) {
+ SDLLogW(@"Attempted to present lock window when it is already presented");
+ return;
+ }
+
+ NSArray* windows = [[UIApplication sharedApplication] windows];
+ UIWindow *appWindow = nil;
+ for (UIWindow *window in windows) {
+ if (window != self.lockWindow) {
+ appWindow = window;
+ break;
}
+ }
+
+ if (appWindow == nil) {
+ SDLLogE(@"Unable to find the app's window");
+ return;
+ }
+
+ [self sdl_presentWithAppWindow:appWindow];
+}
- NSArray* windows = [[UIApplication sharedApplication] windows];
+- (void)sdl_presentIOS13 {
+ SDLLogD(@"Seeking to present lock screen on iOS 13");
+ if (@available(iOS 13.0, *)) {
+ UIWindowScene *appWindowScene = nil;
+ for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
+ SDLLogV(@"Checking scene: %@", scene);
+ // The scene is either foreground active / inactive, background, or unattached. If the latter three, we don't want to do anything with them. Also check that the scene is for the application and not an external display or CarPlay.
+ if ((scene.activationState != UISceneActivationStateForegroundActive) ||
+ (![scene.session.role isEqualToString: UIWindowSceneSessionRoleApplication])) {
+ SDLLogV(@"Skipping scene due to activation state or role");
+ continue;
+ }
+
+ // The scene is foreground active or inactive. Now find the windows.
+ if ([scene isKindOfClass:[UIWindowScene class]]) {
+ appWindowScene = (UIWindowScene *)scene;
+ break;
+ } else {
+ SDLLogV(@"Skipping scene due to it not being a UIWindowScene");
+ continue;
+ }
+ }
+
+ NSArray<UIWindow *> *windows = appWindowScene.windows;
UIWindow *appWindow = nil;
for (UIWindow *window in windows) {
if (window != self.lockWindow) {
+ SDLLogV(@"Found app window");
appWindow = window;
break;
}
@@ -58,69 +113,130 @@ NS_ASSUME_NONNULL_BEGIN
return;
}
- // We let ourselves know that the lockscreen will present, because we have to pause streaming video for that 0.3 seconds or else it will be very janky.
- [[NSNotificationCenter defaultCenter] postNotificationName:SDLLockScreenManagerWillPresentLockScreenViewController object:nil];
+ if (![windows containsObject:self.lockWindow]) {
+ self.lockWindow = [[UIWindow alloc] initWithWindowScene:appWindowScene];
+ self.lockWindow.backgroundColor = [UIColor clearColor];
+ self.lockWindow.rootViewController = self.screenshotViewController;
+ }
+ }
+}
- CGRect firstFrame = appWindow.frame;
- firstFrame.origin.x = CGRectGetWidth(firstFrame);
- appWindow.frame = firstFrame;
+- (void)sdl_presentWithAppWindow:(UIWindow *)appWindow {
+ // We let ourselves know that the lockscreen will present, because we have to pause streaming video for that 0.3 seconds or else it will be very janky.
+ [[NSNotificationCenter defaultCenter] postNotificationName:SDLLockScreenManagerWillPresentLockScreenViewController object:nil];
- // We then move the lockWindow to the original appWindow location.
- self.lockWindow.frame = appWindow.bounds;
- [self.screenshotViewController loadScreenshotOfWindow:appWindow];
- [self.lockWindow makeKeyAndVisible];
+ CGRect firstFrame = appWindow.frame;
+ firstFrame.origin.x = CGRectGetWidth(firstFrame);
+ appWindow.frame = firstFrame;
- // And present the lock screen.
- SDLLogD(@"Present lock screen window");
- [self.lockWindow.rootViewController presentViewController:self.lockViewController animated:YES completion:^{
- // Tell ourselves we are done.
- [[NSNotificationCenter defaultCenter] postNotificationName:SDLLockScreenManagerDidPresentLockScreenViewController object:nil];
- }];
- });
+ // We then move the lockWindow to the original appWindow location.
+ self.lockWindow.frame = appWindow.bounds;
+ [self.screenshotViewController loadScreenshotOfWindow:appWindow];
+ [self.lockWindow makeKeyAndVisible];
+
+ // And present the lock screen.
+ SDLLogD(@"Present lock screen window");
+ [self.lockWindow.rootViewController presentViewController:self.lockViewController animated:YES completion:^{
+ // Tell ourselves we are done.
+ [[NSNotificationCenter defaultCenter] postNotificationName:SDLLockScreenManagerDidPresentLockScreenViewController object:nil];
+ }];
}
+#pragma mark - Dismiss Lock Window
+
- (void)dismiss {
dispatch_async(dispatch_get_main_queue(), ^{
- NSArray* windows = [[UIApplication sharedApplication] windows];
+ if (@available(iOS 13.0, *)) {
+ [self sdl_dismissIOS13];
+ } else {
+ [self sdl_dismissIOS12];
+ }
+ });
+}
+
+- (void)sdl_dismissIOS12 {
+ NSArray* windows = [[UIApplication sharedApplication] windows];
+ UIWindow *appWindow = nil;
+ for (UIWindow *window in windows) {
+ if (window != self.lockWindow) {
+ appWindow = window;
+ break;
+ }
+ }
+
+ [self sdl_dismissWithAppWindow:appWindow];
+}
+
+- (void)sdl_dismissIOS13 {
+ if (@available(iOS 13.0, *)) {
+ UIWindowScene *appWindowScene = nil;
+ for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
+ SDLLogV(@"Checking scene: %@", scene);
+ // The scene is either foreground active / inactive, background, or unattached. If the latter three, we don't want to do anything with them. Also check that the scene is for the application and not an external display or CarPlay.
+ if ((scene.activationState != UISceneActivationStateForegroundActive) ||
+ (![scene.session.role isEqualToString: UIWindowSceneSessionRoleApplication])) {
+ SDLLogV(@"Skipping scene due to activation state or role");
+ continue;
+ }
+
+ // The scene is foreground active or inactive. Now find the windows.
+ if ([scene isKindOfClass:[UIWindowScene class]]) {
+ appWindowScene = (UIWindowScene *)scene;
+ break;
+ } else {
+ SDLLogV(@"Skipping scene due to it not being a UIWindowScene");
+ continue;
+ }
+ }
+
+ NSArray<UIWindow *> *windows = appWindowScene.windows;
UIWindow *appWindow = nil;
for (UIWindow *window in windows) {
if (window != self.lockWindow) {
+ SDLLogV(@"Found app window");
appWindow = window;
break;
}
}
- 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");
- return;
- } else if (self.lockViewController == nil) {
- SDLLogW(@"Attempted to dismiss lock screen, but lockViewController is not set");
- return;
- }
+ [self sdl_dismissWithAppWindow:appWindow];
+ }
+}
- // Let us know we are about to dismiss.
- [[NSNotificationCenter defaultCenter] postNotificationName:SDLLockScreenManagerWillDismissLockScreenViewController object:nil];
+- (void)sdl_dismissWithAppWindow:(UIWindow *)appWindow {
+ 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");
+ return;
+ } else if (self.lockViewController == nil) {
+ SDLLogW(@"Attempted to dismiss lock screen, but lockViewController is not set");
+ return;
+ }
- // Dismiss the lockscreen
- SDLLogD(@"Dismiss lock screen window");
- [self.lockViewController dismissViewControllerAnimated:YES completion:^{
- CGRect lockFrame = self.lockWindow.frame;
- lockFrame.origin.x = CGRectGetWidth(lockFrame);
- self.lockWindow.frame = lockFrame;
+ // Let us know we are about to dismiss.
+ [[NSNotificationCenter defaultCenter] postNotificationName:SDLLockScreenManagerWillDismissLockScreenViewController object:nil];
- // Quickly move the map back, and make it the key window.
- appWindow.frame = self.lockWindow.bounds;
- [appWindow makeKeyAndVisible];
+ // Dismiss the lockscreen
+ SDLLogD(@"Dismiss lock screen window");
+ [self.lockViewController dismissViewControllerAnimated:YES completion:^{
+ CGRect lockFrame = self.lockWindow.frame;
+ lockFrame.origin.x = CGRectGetWidth(lockFrame);
+ self.lockWindow.frame = lockFrame;
- // Tell ourselves we are done.
- [[NSNotificationCenter defaultCenter] postNotificationName:SDLLockScreenManagerDidDismissLockScreenViewController object:nil];
- }];
- });
+ // Quickly move the map back, and make it the key window.
+ appWindow.frame = self.lockWindow.bounds;
+ [appWindow makeKeyAndVisible];
+
+ // Tell ourselves we are done.
+ [[NSNotificationCenter defaultCenter] postNotificationName:SDLLockScreenManagerDidDismissLockScreenViewController object:nil];
+ }];
}
+
+#pragma mark - isPresented Getter
+
- (BOOL)presented {
__block BOOL isPresented = NO;
if ([NSThread isMainThread]) {
diff --git a/SmartDeviceLink/SDLScreenshotViewController.m b/SmartDeviceLink/SDLScreenshotViewController.m
index 9ac5f4a8c..4fbd661d5 100755
--- a/SmartDeviceLink/SDLScreenshotViewController.m
+++ b/SmartDeviceLink/SDLScreenshotViewController.m
@@ -13,6 +13,7 @@
@interface SDLScreenshotViewController ()
@property (nonatomic, strong) UIImageView *imageView;
+@property (nonatomic, strong, nullable) UIWindow *currentAppWindow;
@end
@@ -34,7 +35,9 @@
// HAX: https://github.com/smartdevicelink/sdl_ios/issues/1250
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- UIViewController *viewController = [self sdl_topMostControllerForWindow:[UIApplication sharedApplication].windows[0]];
+ if (self.currentAppWindow == nil) { return UIInterfaceOrientationMaskAll; }
+
+ UIViewController *viewController = [self sdl_topMostControllerForWindow:self.currentAppWindow];
if (viewController == self) {
return UIInterfaceOrientationMaskAll;
@@ -47,7 +50,9 @@
// HAX: https://github.com/smartdevicelink/sdl_ios/issues/1250
- (BOOL)shouldAutorotate {
- UIViewController *viewController = [self sdl_topMostControllerForWindow:[UIApplication sharedApplication].windows[0]];
+ if (self.currentAppWindow == nil) { return UIInterfaceOrientationMaskAll; }
+
+ UIViewController *viewController = [self sdl_topMostControllerForWindow:self.currentAppWindow];
if (viewController == self) {
return YES;
@@ -73,6 +78,9 @@
}
- (void)loadScreenshotOfWindow:(UIWindow *)window {
+ self.currentAppWindow = window;
+ if (self.currentAppWindow == nil) { return; }
+
UIGraphicsBeginImageContextWithOptions(window.bounds.size, YES, 0.0f);
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];