Skip to content

Commit 4c40e0a

Browse files
committed
chore: revert ActivityTracker changes
1 parent a0c4f3a commit 4c40e0a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/ActivityTracking/ActivityTracker.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class ActivityTracker: ActivityTrackerBehaviour {
8181
private let stateMachine: StateMachine<ApplicationState, ActivityEvent>
8282
private var stateMachineSubscriberToken: StateMachineSubscriberToken?
8383

84+
@MainActor
8485
private static let applicationDidMoveToBackgroundNotification: Notification.Name = {
8586
#if canImport(WatchKit)
8687
WKExtension.applicationDidEnterBackgroundNotification
@@ -91,6 +92,7 @@ class ActivityTracker: ActivityTrackerBehaviour {
9192
#endif
9293
}()
9394

95+
@MainActor
9496
private static let applicationWillMoveToForegoundNotification: Notification.Name = {
9597
#if canImport(WatchKit)
9698
WKExtension.applicationWillEnterForegroundNotification
@@ -101,7 +103,8 @@ class ActivityTracker: ActivityTrackerBehaviour {
101103
#endif
102104
}()
103105

104-
nonisolated(unsafe) private static var applicationWillTerminateNotification: Notification.Name = {
106+
@MainActor
107+
private static var applicationWillTerminateNotification: Notification.Name = {
105108
#if canImport(WatchKit)
106109
// There's no willTerminateNotification on watchOS, so using applicationWillResignActive instead.
107110
WKExtension.applicationWillResignActiveNotification
@@ -112,6 +115,7 @@ class ActivityTracker: ActivityTrackerBehaviour {
112115
#endif
113116
}()
114117

118+
@MainActor
115119
private static let notifications = [
116120
applicationDidMoveToBackgroundNotification,
117121
applicationWillMoveToForegoundNotification,
@@ -145,6 +149,7 @@ class ActivityTracker: ActivityTrackerBehaviour {
145149
stateMachineSubscriberToken = stateMachine.subscribe(listener)
146150
}
147151

152+
@MainActor
148153
private func beginBackgroundTracking() {
149154
#if canImport(UIKit) && !os(watchOS)
150155
if backgroundTrackingTimeout > 0 {
@@ -161,6 +166,7 @@ class ActivityTracker: ActivityTrackerBehaviour {
161166
}
162167
}
163168

169+
@MainActor
164170
private func stopBackgroundTracking() {
165171
backgroundTimer = nil
166172
#if canImport(UIKit) && !os(watchOS)
@@ -172,6 +178,7 @@ class ActivityTracker: ActivityTrackerBehaviour {
172178
#endif
173179
}
174180

181+
@MainActor
175182
@objc private func handleApplicationStateChange(_ notification: Notification) {
176183
switch notification.name {
177184
case Self.applicationDidMoveToBackgroundNotification:

AmplifyPlugins/Internal/Tests/InternalAWSPinpointUnitTests/ActivityTrackerTests.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ActivityTrackerTests: XCTestCase {
2020
private var stateMachine: MockStateMachine!
2121
private var timeout: TimeInterval = 1
2222

23+
@MainActor
2324
private static let applicationDidMoveToBackgroundNotification: Notification.Name = {
2425
#if canImport(WatchKit)
2526
WKExtension.applicationDidEnterBackgroundNotification
@@ -30,6 +31,7 @@ class ActivityTrackerTests: XCTestCase {
3031
#endif
3132
}()
3233

34+
@MainActor
3335
private static let applicationWillMoveToForegoundNotification: Notification.Name = {
3436
#if canImport(WatchKit)
3537
WKExtension.applicationWillEnterForegroundNotification
@@ -40,6 +42,7 @@ class ActivityTrackerTests: XCTestCase {
4042
#endif
4143
}()
4244

45+
@MainActor
4346
private static let applicationWillTerminateNotification: Notification.Name = {
4447
#if canImport(WatchKit)
4548
WKExtension.applicationWillResignActiveNotification
@@ -77,9 +80,9 @@ class ActivityTrackerTests: XCTestCase {
7780
stateMachine.processExpectation = expectation(description: "Application state changed")
7881
stateMachine.processExpectation?.expectedFulfillmentCount = 3
7982

80-
NotificationCenter.default.post(Notification(name: Self.applicationDidMoveToBackgroundNotification))
81-
NotificationCenter.default.post(Notification(name: Self.applicationWillMoveToForegoundNotification))
82-
NotificationCenter.default.post(Notification(name: Self.applicationWillTerminateNotification))
83+
await NotificationCenter.default.post(Notification(name: Self.applicationDidMoveToBackgroundNotification))
84+
await NotificationCenter.default.post(Notification(name: Self.applicationWillMoveToForegoundNotification))
85+
await NotificationCenter.default.post(Notification(name: Self.applicationWillTerminateNotification))
8386

8487
await fulfillment(of: [stateMachine.processExpectation!], timeout: 1)
8588
XCTAssertTrue(stateMachine.processedEvents.contains(.applicationDidMoveToBackground))

0 commit comments

Comments
 (0)