summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SmartDeviceLink/SDLLockScreenManager.m50
1 files changed, 31 insertions, 19 deletions
diff --git a/SmartDeviceLink/SDLLockScreenManager.m b/SmartDeviceLink/SDLLockScreenManager.m
index da3f506c4..15f949f43 100644
--- a/SmartDeviceLink/SDLLockScreenManager.m
+++ b/SmartDeviceLink/SDLLockScreenManager.m
@@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (assign, nonatomic) BOOL canPresent;
@property (strong, nonatomic, readwrite) SDLLockScreenConfiguration *config;
@property (strong, nonatomic) id<SDLViewControllerPresentable> presenter;
+@property (strong, nonatomic, nullable) SDLOnLockScreenStatus *lastLockNotification;
@end
@@ -44,6 +45,7 @@ NS_ASSUME_NONNULL_BEGIN
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_lockScreenStatusDidChange:) name:SDLDidChangeLockScreenStatusNotification object:dispatcher];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_lockScreenIconReceived:) name:SDLDidReceiveLockScreenIcon object:dispatcher];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_appDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
return self;
}
@@ -96,44 +98,54 @@ NS_ASSUME_NONNULL_BEGIN
return;
}
- if (self.lockScreenViewController == nil) {
+ self.lastLockNotification = notification.notification;
+ [self sdl_checkLockScreen];
+}
+
+- (void)sdl_lockScreenIconReceived:(NSNotification *)notification {
+ NSAssert([notification.userInfo[SDLNotificationUserInfoObject] isKindOfClass:[UIImage class]], @"A notification was sent with an unanticipated object");
+ if (![notification.userInfo[SDLNotificationUserInfoObject] isKindOfClass:[UIImage class]]) {
return;
}
- SDLOnLockScreenStatus *onLockScreenNotification = notification.notification;
+ UIImage *icon = notification.userInfo[SDLNotificationUserInfoObject];
+
+ // If the VC is our special type, then add the vehicle icon. If they passed in a custom VC, there's no current way to show the vehicle icon. If they're managing it themselves, they can grab the notification themselves.
+ if ([self.lockScreenViewController isKindOfClass:[SDLLockScreenViewController class]]) {
+ ((SDLLockScreenViewController *)self.lockScreenViewController).vehicleIcon = icon;
+ }
+}
+
+- (void)sdl_appDidBecomeActive:(NSNotification *)notification {
+ [self sdl_checkLockScreen];
+}
+
+
+#pragma mark - Private Helpers
+
+- (void)sdl_checkLockScreen {
+ if (self.lockScreenViewController == nil || self.lastLockNotification == nil) {
+ return;
+ }
// Present the VC depending on the lock screen status
- if ([onLockScreenNotification.lockScreenStatus isEqualToEnum:[SDLLockScreenStatus REQUIRED]]) {
+ if ([self.lastLockNotification.lockScreenStatus isEqualToEnum:[SDLLockScreenStatus REQUIRED]]) {
if (!self.presenter.presented && self.canPresent) {
[self.presenter present];
}
- } else if ([onLockScreenNotification.lockScreenStatus isEqualToEnum:[SDLLockScreenStatus OPTIONAL]]) {
+ } else if ([self.lastLockNotification.lockScreenStatus isEqualToEnum:[SDLLockScreenStatus OPTIONAL]]) {
if (self.config.showInOptionalState && !self.presenter.presented && self.canPresent) {
[self.presenter present];
} else if (self.presenter.presented) {
[self.presenter dismiss];
}
- } else if ([onLockScreenNotification.lockScreenStatus isEqualToEnum:[SDLLockScreenStatus OFF]]) {
+ } else if ([self.lastLockNotification.lockScreenStatus isEqualToEnum:[SDLLockScreenStatus OFF]]) {
if (self.presenter.presented) {
[self.presenter dismiss];
}
}
}
-- (void)sdl_lockScreenIconReceived:(NSNotification *)notification {
- NSAssert([notification.userInfo[SDLNotificationUserInfoObject] isKindOfClass:[UIImage class]], @"A notification was sent with an unanticipated object");
- if (![notification.userInfo[SDLNotificationUserInfoObject] isKindOfClass:[UIImage class]]) {
- return;
- }
-
- UIImage *icon = notification.userInfo[SDLNotificationUserInfoObject];
-
- // If the VC is our special type, then add the vehicle icon. If they passed in a custom VC, there's no current way to show the vehicle icon. If they're managing it themselves, they can grab the notification themselves.
- if ([self.lockScreenViewController isKindOfClass:[SDLLockScreenViewController class]]) {
- ((SDLLockScreenViewController *)self.lockScreenViewController).vehicleIcon = icon;
- }
-}
-
@end
NS_ASSUME_NONNULL_END