diff options
author | NicoleYarroch <nicole@livio.io> | 2019-06-25 17:17:58 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2019-06-25 17:17:58 -0400 |
commit | c0b04575cf6d5fb669459dfea975ce24ed102f99 (patch) | |
tree | c33a3a77b2344ee94e10a9ce3b1ddac4e6b2ffc7 | |
parent | 14e1f5e4df014938a555f683a1bfe542926e3acc (diff) | |
download | sdl_ios-bugfix/issue_1316_background_task_session_creation_fails.tar.gz |
-rw-r--r-- | SmartDeviceLink/SDLBackgroundTaskManager.m | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/SmartDeviceLink/SDLBackgroundTaskManager.m b/SmartDeviceLink/SDLBackgroundTaskManager.m index 63917fd66..df77ade5f 100644 --- a/SmartDeviceLink/SDLBackgroundTaskManager.m +++ b/SmartDeviceLink/SDLBackgroundTaskManager.m @@ -14,8 +14,9 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLBackgroundTaskManager () -@property (nonatomic, assign) NSString *backgroundTaskName; -@property (nonatomic, assign) UIBackgroundTaskIdentifier backgroundTaskId; +@property (copy, nonatomic) NSString *backgroundTaskName; +@property (assign, nonatomic) UIBackgroundTaskIdentifier currentBackgroundTaskId; + @end @implementation SDLBackgroundTaskManager @@ -36,18 +37,18 @@ NS_ASSUME_NONNULL_BEGIN * Starts a background task that allows the app to establish a session while app is backgrounded. If the app is not currently backgrounded, the background task will remain dormant until the app moves to the background. */ - (void)startBackgroundTask { - if (self.backgroundTaskId != UIBackgroundTaskInvalid) { + if (self.currentBackgroundTaskId != UIBackgroundTaskInvalid) { SDLLogV(@"The %@ background task is already running.", self.backgroundTaskName); return; } __weak typeof(self) weakself = self; - self.backgroundTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithName:self.backgroundTaskName expirationHandler:^{ + self.currentBackgroundTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithName:self.backgroundTaskName expirationHandler:^{ SDLLogD(@"The %@ background task expired", self.backgroundTaskName); [weakself endBackgroundTask]; }]; - SDLLogD(@"The %@ background task started with id: %lu", self.backgroundTaskName, (unsigned long)self.backgroundTaskId); + SDLLogD(@"The %@ background task started with id: %lu", self.backgroundTaskName, (unsigned long)self.currentBackgroundTaskId); } /** @@ -58,14 +59,14 @@ NS_ASSUME_NONNULL_BEGIN * */ - (void)endBackgroundTask { - if (self.backgroundTaskId == UIBackgroundTaskInvalid) { + if (self.currentBackgroundTaskId == UIBackgroundTaskInvalid) { SDLLogV(@"Background task already ended. Returning..."); return; } - SDLLogD(@"Ending background task with id: %lu", (unsigned long)self.backgroundTaskId); - [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskId]; - self.backgroundTaskId = UIBackgroundTaskInvalid; + SDLLogD(@"Ending background task with id: %lu", (unsigned long)self.currentBackgroundTaskId); + [[UIApplication sharedApplication] endBackgroundTask:self.currentBackgroundTaskId]; + self.currentBackgroundTaskId = UIBackgroundTaskInvalid; } @end |