diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2017-02-16 16:46:47 -0500 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2017-02-16 16:46:47 -0500 |
commit | 61e6f87b536bc33b944f42be7bad6786c0bab4d1 (patch) | |
tree | fbf6c7b0cce759a45266b7903a9fea9b339bacb6 | |
parent | 9d783d9cc4e4d5f712ae1772afcfb272ea23c61a (diff) | |
download | sdl_ios-61e6f87b536bc33b944f42be7bad6786c0bab4d1.tar.gz |
SDLLockScreenManager now tracks active state to show lock screen when the app becomes active if it was not shown before
-rw-r--r-- | SmartDeviceLink/SDLLockScreenManager.m | 50 |
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 |