diff options
author | NicoleYarroch <nicole@livio.io> | 2020-06-16 12:04:06 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2020-06-16 12:04:06 -0400 |
commit | 693b03f5b9d4732cf28acef091598ac5f0e31a5e (patch) | |
tree | 1fd1e84fca8e5bc7ec4fb5c78cb4778de273d629 | |
parent | 2d42f7bb8641ef33c56bb22cea30b64576b2a9c2 (diff) | |
download | sdl_ios-693b03f5b9d4732cf28acef091598ac5f0e31a5e.tar.gz |
Refactored dispatches
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r-- | SmartDeviceLink/SDLLockScreenManager.m | 25 | ||||
-rw-r--r-- | SmartDeviceLink/SDLLockScreenPresenter.m | 17 |
2 files changed, 12 insertions, 30 deletions
diff --git a/SmartDeviceLink/SDLLockScreenManager.m b/SmartDeviceLink/SDLLockScreenManager.m index d303f8690..1d4bc9e4a 100644 --- a/SmartDeviceLink/SDLLockScreenManager.m +++ b/SmartDeviceLink/SDLLockScreenManager.m @@ -69,7 +69,7 @@ NS_ASSUME_NONNULL_BEGIN self.canPresent = NO; __weak typeof(self) weakSelf = self; - [self sdl_runOnMainQueue:^{ + dispatch_async(dispatch_get_main_queue(), ^{ __strong typeof(weakSelf) strongSelf = weakSelf; if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) { @@ -86,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN } else { [strongSelf sdl_start]; } - }]; + }); } - (void)sdl_start { @@ -159,7 +159,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)sdl_appDidBecomeActive:(NSNotification *)notification { __weak typeof(self) weakSelf = self; - [self sdl_runOnMainQueue:^{ + dispatch_async(dispatch_get_main_queue(), ^{ __strong typeof(weakSelf) strongSelf = weakSelf; // Restart, and potentially dismiss the lock screen if the app was disconnected in the background if (!strongSelf.canPresent) { @@ -167,7 +167,7 @@ NS_ASSUME_NONNULL_BEGIN } [strongSelf sdl_checkLockScreen]; - }]; + }); } - (void)sdl_driverDistractionStateDidChange:(SDLRPCNotificationNotification *)notification { @@ -187,9 +187,9 @@ NS_ASSUME_NONNULL_BEGIN } __weak typeof(self) weakSelf = self; - [self sdl_runOnMainQueue:^{ + dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf sdl_updatePresentation]; - }]; + }); } - (void)sdl_updatePresentation { @@ -248,7 +248,7 @@ NS_ASSUME_NONNULL_BEGIN } __weak typeof(self) weakSelf = self; - [self sdl_runOnMainQueue:^{ + dispatch_async(dispatch_get_main_queue(), ^{ __strong typeof(self) strongSelf = weakSelf; SDLLockScreenViewController *lockscreenViewController = (SDLLockScreenViewController *)strongSelf.lockScreenViewController; if (enabled) { @@ -261,16 +261,7 @@ NS_ASSUME_NONNULL_BEGIN [lockscreenViewController removeDismissGesture]; lockscreenViewController.lockedLabelText = nil; } - }]; -} - -#pragma mark - Threading Utilities - -/// Dispatches the block to the main queue. -/// @discussion Used to ensure that updates to the lock screen UI are done on the main thread -/// @param block The block to be executed -- (void)sdl_runOnMainQueue:(void (^)(void))block { - dispatch_async(dispatch_get_main_queue(), block); + }); } @end diff --git a/SmartDeviceLink/SDLLockScreenPresenter.m b/SmartDeviceLink/SDLLockScreenPresenter.m index 1175670d9..03bca9e0a 100644 --- a/SmartDeviceLink/SDLLockScreenPresenter.m +++ b/SmartDeviceLink/SDLLockScreenPresenter.m @@ -110,7 +110,7 @@ NS_ASSUME_NONNULL_BEGIN } __weak typeof(self) weakself = self; - [self sdl_runOnMainQueue:^{ + dispatch_async(dispatch_get_main_queue(), ^{ __typeof(weakself) strongself = weakself; if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) { // If the the `UIWindow` is created while the app is backgrounded and the app is using `SceneDelegate` class (iOS 13+), then the window will not be created correctly. Wait until the app is foregrounded before creating the window. @@ -146,7 +146,7 @@ NS_ASSUME_NONNULL_BEGIN if (completionHandler == nil) { return; } return completionHandler(); }]; - }]; + }); } @@ -162,14 +162,14 @@ NS_ASSUME_NONNULL_BEGIN } __weak typeof(self) weakSelf = self; - [self sdl_runOnMainQueue:^{ + dispatch_async(dispatch_get_main_queue(), ^{ if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) { SDLLogV(@"Application is backgrounded. The lockscreen will not be dismissed until the app is brought to the foreground."); if (completionHandler == nil) { return; } return completionHandler(NO); } [weakSelf sdl_dismissLockscreenWithCompletionHandler:completionHandler]; - }]; + }); } /// Handles the dismissal of the lockscreen with animation. @@ -208,15 +208,6 @@ NS_ASSUME_NONNULL_BEGIN }]; } -#pragma mark - Threading Utilities - -/// Dispatches the block to the main queue. -/// @discussion Used to ensure that updates to the lock screen UI are done on the main thread -/// @param block The block to be executed -- (void)sdl_runOnMainQueue:(void (^)(void))block { - dispatch_async(dispatch_get_main_queue(), block); -} - #pragma mark - Custom Presented / Dismissed Getters /// Returns whether or not the lockViewController is currently presented or currently animating the presentation of the lockscreen |