summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2017-03-02 10:19:09 -0500
committerGitHub <noreply@github.com>2017-03-02 10:19:09 -0500
commit708f085f5e3e976f0019e768e0cf5631b4575432 (patch)
treeb6127c0418c406a5dcfb6fc6ad37c0c58a84605a
parent16104d97b753bce1795798b3a2852a91b62cde4a (diff)
parent8f92e6194a538004da32011155cc8c9c6faedcce (diff)
downloadsdl_ios-708f085f5e3e976f0019e768e0cf5631b4575432.tar.gz
Merge pull request #548 from smartdevicelink/hotfix/issue_538
Lock screen track phone app state
-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