Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '15.2'
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: /Users/runner/Library/Developer/Xcode/DerivedData
key: ${{ runner.os }}-spm-examples-${{ hashFiles('**/Package.resolved') }}
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ let package = Package(
platforms: [
.iOS("13.0"),
.tvOS("11.0"),
.watchOS("7.1")
.watchOS("7.1"),
.macOS(.v10_15)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand Down
51 changes: 35 additions & 16 deletions Sources/SegmentAmplitude/AmplitudeSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@

import Foundation
import Segment
#if !os(macOS)
import UIKit
#endif


@objc(SEGAmplitudeSession)
public class ObjCAmplitudeSession: NSObject, ObjCPlugin, ObjCPluginShim {
public func instance() -> EventPlugin { return AmplitudeSession() }
}

public class AmplitudeSession: EventPlugin, iOSLifecycle {
public class AmplitudeSession: EventPlugin {
public var key = "Actions Amplitude"
public var type = PluginType.enrichment
public weak var analytics: Analytics?
Expand Down Expand Up @@ -146,36 +148,53 @@ public class AmplitudeSession: EventPlugin, iOSLifecycle {
public func reset() {
resetSession()
}

}

extension AmplitudeSession: VersionedPlugin {
public static func version() -> String {
return __destination_version
}

}

// MARK: - Platform-Specific Lifecycle Support

#if os(iOS) || os(tvOS)
extension AmplitudeSession: iOSLifecycle {
public func applicationWillEnterForeground(application: UIApplication?) {
startNewSessionIfNecessary()
debugLog("Foreground: \(eventSessionID)")
}

public func applicationWillResignActive(application: UIApplication?) {
debugLog("Background: \(eventSessionID)")
_lastEventTime.set(newTimestamp())
}
}

extension AmplitudeSession: VersionedPlugin {
public static func version() -> String {
return __destination_version
}

}
#if os(watchOS)
#elseif os(watchOS)
extension AmplitudeSession: watchOSLifecycle {
public func applicationWillEnterForeground(watchExtension: WKExtension) {
startNewSessionIfNecessary()
debugLog("Foreground: \(eventSessionID)")
}
startNewSessionIfNecessary()
debugLog("Foreground: \(eventSessionID)")
}

public func applicationWillResignActive(watchExtension: WKExtension) {
debugLog("Background: \(eventSessionID)")
_lastEventTime.set(newTimestamp())
}
}
}
#elseif os(macOS)
extension AmplitudeSession: macOSLifecycle {
public func applicationWillBecomeActive() {
startNewSessionIfNecessary()
debugLog("Foreground: \(eventSessionID)")
}

public func applicationWillResignActive() {
debugLog("Background: \(eventSessionID)")
_lastEventTime.set(newTimestamp())
}
}
#endif


Expand Down