From cba4af9ce8c0fcc7b2ddd94f6ff1ffbb38586a34 Mon Sep 17 00:00:00 2001 From: Kyle Hedden Date: Wed, 14 Jun 2023 19:47:26 -0400 Subject: [PATCH] Allow session handler objects to be initialized without MainActor to inline session creation with async await incompatible code. Fixes a Main thread dispatch clash. --- .../MVMCore/Session/MVMCoreSessionTimeHandler.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift index 068d0d2..7f8d0ef 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift @@ -25,12 +25,14 @@ return MVMCoreActionUtility.fatalClassCheck(object: MVMCoreObject.sharedInstance()?.sessionHandler) } - public override init() { + nonisolated public override init() { super.init() - // Adds notifications for if the app entered the background/foreground. - NotificationCenter.default.addObserver(self, selector: #selector(appEnteredBackground), name: UIApplication.didEnterBackgroundNotification, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(appEnteredForeground), name: UIApplication.willEnterForegroundNotification, object: nil) - resetStartTime() + + Task { @MainActor in + // Adds notifications for if the app entered the background/foreground. + NotificationCenter.default.addObserver(self, selector: #selector(appEnteredBackground), name: UIApplication.didEnterBackgroundNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(appEnteredForeground), name: UIApplication.willEnterForegroundNotification, object: nil) + } } deinit {