From 3fa4cda39df6ed4fcb107ca4376483f9a6354b33 Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Mon, 31 Jul 2023 20:55:44 +0200 Subject: [PATCH] `Paywalls`: added a few more logs (#2927) Also improved logging by using `verboseLogHandler` and a new `Strings` enum. --- RevenueCatUI/Data/Strings.swift | 45 +++++++++++++++++++ .../Data/TemplateViewConfiguration.swift | 2 +- RevenueCatUI/Data/Variables.swift | 2 +- RevenueCatUI/Helpers/Logger.swift | 34 ++++++++++++-- RevenueCatUI/View+PresentPaywall.swift | 7 +++ 5 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 RevenueCatUI/Data/Strings.swift diff --git a/RevenueCatUI/Data/Strings.swift b/RevenueCatUI/Data/Strings.swift new file mode 100644 index 0000000000..3e52482146 --- /dev/null +++ b/RevenueCatUI/Data/Strings.swift @@ -0,0 +1,45 @@ +// +// Strings.swift +// +// +// Created by Nacho Soto on 7/31/23. +// + +import Foundation +import RevenueCat + +// swiftlint:disable variable_name + +enum Strings { + + case found_multiple_packages_of_same_type(PackageType) + case could_not_find_content_for_variable(variableName: String) + + case determining_whether_to_display_paywall + case displaying_paywall + case not_displaying_paywall + +} + +extension Strings: CustomStringConvertible { + + var description: String { + switch self { + case let .found_multiple_packages_of_same_type(type): + return "Found multiple \(type) packages. Will use the first one." + + case let .could_not_find_content_for_variable(variableName): + return "Couldn't find content for variable '\(variableName)'" + + case .determining_whether_to_display_paywall: + return "Determining whether to display paywall" + + case .displaying_paywall: + return "Condition met: will display paywall" + + case .not_displaying_paywall: + return "Condition not met: will not display paywall" + } + } + +} diff --git a/RevenueCatUI/Data/TemplateViewConfiguration.swift b/RevenueCatUI/Data/TemplateViewConfiguration.swift index 4cbabac66d..a050209e8a 100644 --- a/RevenueCatUI/Data/TemplateViewConfiguration.swift +++ b/RevenueCatUI/Data/TemplateViewConfiguration.swift @@ -154,7 +154,7 @@ extension TemplateViewConfiguration { case 1: return packages.first default: - Logger.warning("Found multiple \(type) packages. Will use the first one.") + Logger.warning(Strings.found_multiple_packages_of_same_type(type)) return packages.first } } else { diff --git a/RevenueCatUI/Data/Variables.swift b/RevenueCatUI/Data/Variables.swift index 351aefe2ca..5c03043566 100644 --- a/RevenueCatUI/Data/Variables.swift +++ b/RevenueCatUI/Data/Variables.swift @@ -105,7 +105,7 @@ private extension VariableDataProvider { return self.introductoryOfferDuration(locale) ?? "" default: - Logger.warning("Couldn't find content for variable '\(variableName)'") + Logger.warning(Strings.could_not_find_content_for_variable(variableName: variableName)) return "" } } diff --git a/RevenueCatUI/Helpers/Logger.swift b/RevenueCatUI/Helpers/Logger.swift index 715f710612..9d5d195a25 100644 --- a/RevenueCatUI/Helpers/Logger.swift +++ b/RevenueCatUI/Helpers/Logger.swift @@ -7,12 +7,38 @@ import RevenueCat +// Note: this isn't ideal. +// Once we can use the `package` keyword it can use the internal `Logger`. enum Logger { - static func warning(_ text: String) { - // Note: this isn't ideal. - // Once we can use the `package` keyword it can use the internal `Logger`. - Purchases.logHandler(.warn, text) + static func debug( + _ text: CustomStringConvertible, + file: String = #file, + function: String = #function, + line: UInt = #line + ) { + Purchases.verboseLogHandler( + .debug, + text.description, + file, + function, + line + ) + } + + static func warning( + _ text: CustomStringConvertible, + file: String = #file, + function: String = #function, + line: UInt = #line + ) { + Purchases.verboseLogHandler( + .warn, + text.description, + file, + function, + line + ) } } diff --git a/RevenueCatUI/View+PresentPaywall.swift b/RevenueCatUI/View+PresentPaywall.swift index 8aab649238..3debfcc5af 100644 --- a/RevenueCatUI/View+PresentPaywall.swift +++ b/RevenueCatUI/View+PresentPaywall.swift @@ -74,8 +74,15 @@ private struct PresentingPaywallModifier: ViewModifier { } .task { guard let info = try? await Purchases.shared.customerInfo() else { return } + + Logger.debug(Strings.determining_whether_to_display_paywall) + if self.shouldDisplay(info) { + Logger.debug(Strings.displaying_paywall) + self.isDisplayed = true + } else { + Logger.debug(Strings.not_displaying_paywall) } } }