Skip to content

Commit

Permalink
debugRevenueCatOverlay: display receiptURL (#2652)
Browse files Browse the repository at this point in the history
Useful when debugging issues like #2558.

![Screenshot 2023-06-14 at 11 58
28](https://github.com/RevenueCat/purchases-ios/assets/685609/3fcb55bc-107e-46fd-aced-0d12d0667cba)
  • Loading branch information
NachoSoto authored Jun 15, 2023
1 parent 1b2f7f9 commit 6ba378b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,10 @@ internal extension Purchases {
return self.systemInfo.responseVerificationMode.publicKey
}

var receiptURL: URL? {
return self.receiptFetcher.receiptURL
}

}

#endif
Expand Down
43 changes: 33 additions & 10 deletions Sources/Support/DebugUI/DebugContentViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
import StoreKit
import SwiftUI

#if os(macOS)
import AppKit
#endif

// swiftlint:disable file_length

@available(iOS 16.0, macOS 13.0, *)
struct DebugSwiftUIRootView: View {

Expand Down Expand Up @@ -113,18 +119,35 @@ internal struct DebugSummaryView: View {
Text("Loading...")

case let .loaded(config):
LabeledContent("SDK version", value: config.sdkVersion)
LabeledContent("Observer mode", value: config.observerMode.description)
LabeledContent("Sandbox", value: config.sandbox.description)
LabeledContent("StoreKit 2", value: config.storeKit2Enabled ? "on" : "off")
LabeledContent("Offline Customer Info",
value: config.offlineCustomerInfoSupport ? "enabled" : "disabled")
LabeledContent("Entitlement Verification Mode", value: config.verificationMode)

ShareLink(item: config, preview: .init("Configuration")) {
Label("Share", systemImage: "square.and.arrow.up")
Group {
LabeledContent("SDK version", value: config.sdkVersion)
LabeledContent("Observer mode", value: config.observerMode.description)
LabeledContent("Sandbox", value: config.sandbox.description)
LabeledContent("StoreKit 2", value: config.storeKit2Enabled ? "on" : "off")
LabeledContent("Offline Customer Info",
value: config.offlineCustomerInfoSupport ? "enabled" : "disabled")
LabeledContent("Entitlement Verification Mode", value: config.verificationMode)
LabeledContent("Receipt URL", value: config.receiptURL?.absoluteString ?? "")
#if os(macOS)
.contextMenu {
Button {
if let url = config.receiptURL {
NSWorkspace.shared.selectFile(
nil,
inFileViewerRootedAtPath: url.deletingLastPathComponent().path
)
}
} label: {
Text("Show in Finder")
}
}
#endif

ShareLink(item: config, preview: .init("Configuration")) {
Label("Share", systemImage: "square.and.arrow.up")
}
}
.textSelection(.enabled)
.frame(maxWidth: .infinity)
}
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/Support/DebugUI/DebugViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class DebugViewModel: ObservableObject {
var storeKit2Enabled: Bool
var offlineCustomerInfoSupport: Bool
var verificationMode: String
var receiptURL: URL?

}

Expand Down Expand Up @@ -125,7 +126,8 @@ private extension DebugViewModel.Configuration {
sandbox: purchases.isSandbox,
storeKit2Enabled: purchases.storeKit2Setting.isEnabledAndAvailable,
offlineCustomerInfoSupport: purchases.offlineCustomerInfoEnabled,
verificationMode: purchases.responseVerificationMode.display
verificationMode: purchases.responseVerificationMode.display,
receiptURL: purchases.receiptURL
)
}

Expand Down
3 changes: 2 additions & 1 deletion Tests/UnitTests/Support/DebugViewSwiftUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class DebugViewSwiftUITests: TestCase {
sandbox: true,
storeKit2Enabled: true,
offlineCustomerInfoSupport: true,
verificationMode: "Enforced"
verificationMode: "Enforced",
receiptURL: URL(string: "file://receipt")
))
model.diagnosticsResult = .loaded(())
model.customerInfo = .loaded(try Self.mockCustomerInfo)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6ba378b

Please sign in to comment.