Skip to content

Commit

Permalink
Paywalls: added a few more logs (#2927)
Browse files Browse the repository at this point in the history
Also improved logging by using `verboseLogHandler` and a new `Strings`
enum.
  • Loading branch information
NachoSoto committed Sep 15, 2023
1 parent 150a7fd commit 3dffee3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
45 changes: 45 additions & 0 deletions RevenueCatUI/Data/Strings.swift
Original file line number Diff line number Diff line change
@@ -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"
}
}

}
2 changes: 1 addition & 1 deletion RevenueCatUI/Data/TemplateViewConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion RevenueCatUI/Data/Variables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
}
Expand Down
34 changes: 30 additions & 4 deletions RevenueCatUI/Helpers/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

}
7 changes: 7 additions & 0 deletions RevenueCatUI/View+PresentPaywall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 3dffee3

Please sign in to comment.