Skip to content

Commit d6b1d46

Browse files
fix: support for watchOSLifecycle (#31)
1 parent 85c65f1 commit d6b1d46

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Sources/SegmentAmplitude/AmplitudeSession.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import Foundation
3030
import Segment
3131
import UIKit
3232

33+
3334
@objc(SEGAmplitudeSession)
3435
public class ObjCAmplitudeSession: NSObject, ObjCPlugin, ObjCPluginShim {
3536
public func instance() -> EventPlugin { return AmplitudeSession() }
@@ -161,7 +162,21 @@ extension AmplitudeSession: VersionedPlugin {
161162
public static func version() -> String {
162163
return __destination_version
163164
}
165+
164166
}
167+
#if os(watchOS)
168+
extension AmplitudeSession: watchOSLifecycle {
169+
public func applicationWillEnterForeground(watchExtension: WKExtension) {
170+
startNewSessionIfNecessary()
171+
debugLog("Foreground: \(eventSessionID)")
172+
}
173+
174+
public func applicationWillResignActive(watchExtension: WKExtension) {
175+
debugLog("Background: \(eventSessionID)")
176+
_lastEventTime.set(newTimestamp())
177+
}
178+
}
179+
#endif
165180

166181

167182
// MARK: - AmplitudeSession Helper Methods

0 commit comments

Comments
 (0)