Skip to content

Commit

Permalink
Fix watchOS platform building issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Dec 25, 2024
1 parent a53101e commit 5ffc57a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Sources/TelemetryDeck/Helpers/DurationSignalTracker.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#if canImport(UIKit)
#if canImport(WatchKit)
import WatchKit
#elseif canImport(UIKit)
import UIKit
#elseif canImport(AppKit)
import AppKit
#endif

@MainActor
@available(watchOS 7.0, *)
final class DurationSignalTracker {
static let shared = DurationSignalTracker()

Expand Down Expand Up @@ -33,7 +36,21 @@ final class DurationSignalTracker {
}

private func setupAppLifecycleObservers() {
#if canImport(UIKit)
#if canImport(WatchKit)
NotificationCenter.default.addObserver(
self,
selector: #selector(handleDidEnterBackgroundNotification),
name: WKApplication.didEnterBackgroundNotification,
object: nil
)

NotificationCenter.default.addObserver(
self,
selector: #selector(handleWillEnterForegroundNotification),
name: WKApplication.willEnterForegroundNotification,
object: nil
)
#elseif canImport(UIKit)
NotificationCenter.default.addObserver(
self,
selector: #selector(handleDidEnterBackgroundNotification),
Expand Down
2 changes: 2 additions & 0 deletions Sources/TelemetryDeck/TelemetryDeck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public enum TelemetryDeck {
///
/// If a new duration signal ist started while an existing duration signal with the same name was not stopped yet, the old one is replaced with the new one.
@MainActor
@available(watchOS 7.0, *)
static func startDurationSignal(_ signalName: String, parameters: [String: String] = [:]) {
DurationSignalTracker.shared.startTracking(signalName, parameters: parameters)
}
Expand All @@ -111,6 +112,7 @@ public enum TelemetryDeck {
///
/// If no matching signal was started, this function does nothing.
@MainActor
@available(watchOS 7.0, *)
static func stopAndSendDurationSignal(_ signalName: String, parameters: [String: String] = [:]) {
guard let (duration, startParameters) = DurationSignalTracker.shared.stopTracking(signalName) else { return }

Expand Down

0 comments on commit 5ffc57a

Please sign in to comment.