Skip to content

Commit cd47dda

Browse files
committed
Fix Background Task Manager
* Removed `weak` reference to delegate as it was immediately null after being set in startup code * Therefore, all calls to the delegate were falling through the guard statement
1 parent 94065af commit cd47dda

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSBackgroundTaskManager.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
import Foundation
29+
import OneSignalCore
2930

3031
@objc
3132
public protocol OSBackgroundTaskManagerDelegate {
@@ -39,12 +40,12 @@ public protocol OSBackgroundTaskManagerDelegate {
3940
// check if Core needs to use this, then ok to live here
4041
@objc
4142
public class OSBackgroundTaskManager: NSObject {
42-
@objc public static weak var delegate: OSBackgroundTaskManagerDelegate?
43+
@objc public static var delegate: OSBackgroundTaskManagerDelegate? // TODO: This used to be weak, is that still necessary
4344

4445
@objc
4546
public static func beginBackgroundTask(_ taskIdentifier: String) {
4647
guard let delegate = delegate else {
47-
// Log error, no delegate
48+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSBackgroundTaskManager:beginBackgroundTask \(taskIdentifier) cannot be executed due to no delegate.")
4849
return
4950
}
5051
delegate.beginBackgroundTask(taskIdentifier)
@@ -53,7 +54,7 @@ public class OSBackgroundTaskManager: NSObject {
5354
@objc
5455
public static func endBackgroundTask(_ taskIdentifier: String) {
5556
guard let delegate = delegate else {
56-
// Log error, no delegate
57+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSBackgroundTaskManager:endBackgroundTask \(taskIdentifier) cannot be executed due to no delegate.")
5758
return
5859
}
5960
delegate.endBackgroundTask(taskIdentifier)
@@ -62,7 +63,7 @@ public class OSBackgroundTaskManager: NSObject {
6263
@objc
6364
public static func setTaskInvalid(_ taskIdentifier: String) {
6465
guard let delegate = delegate else {
65-
// Log error, no delegate
66+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSBackgroundTaskManager:setTaskInvalid \(taskIdentifier) cannot be executed due to no delegate.")
6667
// But not necessarily an error because this task won't exist
6768
// Can be called in initialization of services before delegate is set
6869
return

0 commit comments

Comments
 (0)