From 4a18c11362541c24dd0c099de2187946ed515c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Sat, 6 Jul 2024 08:07:45 +0200 Subject: [PATCH] Adds support for accessing the Storefront country code on visionOS --- .../Presets/TelemetryDeck+Purchases.swift | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Sources/TelemetryClient/Presets/TelemetryDeck+Purchases.swift b/Sources/TelemetryClient/Presets/TelemetryDeck+Purchases.swift index e8b9091..f414e45 100644 --- a/Sources/TelemetryClient/Presets/TelemetryDeck+Purchases.swift +++ b/Sources/TelemetryClient/Presets/TelemetryDeck+Purchases.swift @@ -23,7 +23,7 @@ extension TelemetryDeck { let priceValueInUSD: Double - if #available(iOS 16, macOS 13, tvOS 16, visionOS 1, watchOS 9, *) { + if #available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) { if transaction.currency?.identifier == "USD" { priceValueInUSD = priceValueInNativeCurrency } else if @@ -47,18 +47,23 @@ extension TelemetryDeck { } } - #if os(visionOS) - let countryCode = "US" // NOTE: visionOS 1.x does not support the `storefrontCountryCode` field - #else - let countryCode = transaction.storefrontCountryCode - #endif + let countryCode: String + if #available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) { + countryCode = transaction.storefront.countryCode + } else { + #if os(visionOS) + countryCode = "US" + #else + countryCode = transaction.storefrontCountryCode + #endif + } var purchaseParameters: [String: String] = [ "TelemetryDeck.Purchase.type": transaction.subscriptionGroupID != nil ? "subscription" : "one-time-purchase", "TelemetryDeck.Purchase.countryCode": countryCode, ] - if #available(iOS 16, macOS 13, tvOS 16, visionOS 1, watchOS 9, *) { + if #available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) { if let currencyCode = transaction.currency?.identifier { purchaseParameters["TelemetryDeck.Purchase.currencyCode"] = currencyCode }