Skip to content

Commit 31777fc

Browse files
committed
Fix incompatibilities with watchOS and tvOS
Fix #11
1 parent 99a3bb2 commit 31777fc

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Sources/TelemetryClient/TelemetryClient.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ import CommonCrypto
1212
import UIKit
1313
#endif
1414

15+
#if os(watchOS)
16+
import WatchKit
17+
#endif
18+
19+
#if os(tvOS)
20+
import TVUIKit
21+
#endif
22+
1523
public typealias TelemetrySignalType = String
1624
public struct TelemetryManagerConfiguration {
1725
public let telemetryAppID: String
@@ -135,7 +143,7 @@ private extension TelemetryManager {
135143
#elseif os(iOS)
136144
return "\(platform) \(UIDevice.current.systemVersion)"
137145
#elseif os(watchOS)
138-
return "\(platform) \(UIDevice.current.systemVersion)"
146+
return "\(platform) \(WKInterfaceDevice.current().systemVersion)"
139147
#elseif os(tvOS)
140148
return "\(platform) \(UIDevice.current.systemVersion)"
141149
#else
@@ -159,10 +167,16 @@ private extension TelemetryManager {
159167
/// and build number (in which case it's strongly recommended to supply an email or UUID or similar identifier for
160168
/// your user yourself.
161169
var defaultUserIdentifier: String {
162-
#if os(macOS)
163-
return "unknown user \(systemVersion) \(buildNumber)"
164-
#else
170+
#if os(iOS)
165171
return UIDevice.current.identifierForVendor?.uuidString ?? "unknown user \(systemVersion) \(buildNumber)"
172+
#elseif os(watchOS)
173+
if #available(watchOS 6.2, *) {
174+
return WKInterfaceDevice.current().identifierForVendor?.uuidString ?? "unknown user \(systemVersion) \(buildNumber)"
175+
} else {
176+
return "unknown user \(platform) \(systemVersion) \(buildNumber)"
177+
}
178+
#else
179+
return "unknown user \(platform) \(systemVersion) \(buildNumber)"
166180
#endif
167181
}
168182

0 commit comments

Comments
 (0)