Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The changelog for `SuperwallKit`. Also see the [releases](https://github.com/sup

- Fixes issue with compiling on Xcode 26.4 beta.
- Fixes dashboard display of multiple active entitlements.
- Makes `device.isSandbox` more reliable.

## 4.13.0

Expand Down
7 changes: 7 additions & 0 deletions Sources/SuperwallKit/Network/Device Helper/DeviceHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ class DeviceHelper {
return "true"
#else

// Prefer AppTransaction.environment (iOS 16+) when available,
// as it reliably detects sandbox for all purchase types including
// Stripe and non-StoreKit flows.
if let isSandbox = ReceiptManager.isSandboxEnvironment {
return "\(isSandbox)"
}

guard let url = Bundle.main.appStoreReceiptURL else {
return "false"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ actor ReceiptManager {
private unowned let storage: Storage
static var appTransactionId: String?
static var appId: UInt64?
/// Set from `AppTransaction.shared` when available (iOS 16+).
/// `true` means sandbox, `false` means production, `nil` means not yet determined.
static var isSandboxEnvironment: Bool?

init(
storeKitVersion: SuperwallOptions.StoreKitVersion,
Expand Down Expand Up @@ -91,6 +94,7 @@ actor ReceiptManager {
.unverified(let transaction, _):
Self.appTransactionId = transaction.appTransactionID
Self.appId = transaction.appID
Self.isSandboxEnvironment = transaction.environment == .sandbox || transaction.environment == .xcode
if Superwall.isInitialized {
registerAppTransactionIdIfNeeded()
Superwall.shared.dequeueIntegrationAttributes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,27 @@ class ReceiptManagerTests: XCTestCase {
}

func test_isFreeTrialAvailable() {


}

func test_isSandboxEnvironment_defaultsToNil() {
// Reset to default state
ReceiptManager.isSandboxEnvironment = nil
XCTAssertNil(ReceiptManager.isSandboxEnvironment)
}

func test_isSandboxEnvironment_canBeSetToTrue() {
ReceiptManager.isSandboxEnvironment = true
XCTAssertEqual(ReceiptManager.isSandboxEnvironment, true)
// Clean up
ReceiptManager.isSandboxEnvironment = nil
}

func test_isSandboxEnvironment_canBeSetToFalse() {
ReceiptManager.isSandboxEnvironment = false
XCTAssertEqual(ReceiptManager.isSandboxEnvironment, false)
// Clean up
ReceiptManager.isSandboxEnvironment = nil
}
/*
// MARK: - Test processing of receipt data
Expand Down
Loading