Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Entitlements Computation: fix support display on debug screen #4215

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
4 changes: 4 additions & 0 deletions Sources/Misc/SystemInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ class SystemInfo {
self.preferredLocalesProvider = preferredLocalesProvider
}

var supportsOfflineEntitlements: Bool {
!self.observerMode && !self.dangerousSettings.customEntitlementComputation
}

/// Asynchronous API if caller can't ensure that it's invoked in the `@MainActor`
/// - Seealso: `isApplicationBackgrounded`
func isApplicationBackgrounded(completion: @escaping @Sendable (Bool) -> Void) {
Expand Down
3 changes: 1 addition & 2 deletions Sources/OfflineEntitlements/OfflineEntitlementsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class OfflineEntitlementsManager {
completion: (@MainActor @Sendable (Result<(), Error>) -> Void)?
) {
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *),
!self.systemInfo.observerMode,
!self.systemInfo.dangerousSettings.customEntitlementComputation else {
self.systemInfo.supportsOfflineEntitlements else {
Logger.debug(Strings.offlineEntitlements.product_entitlement_mapping_unavailable)

self.dispatchCompletionOnMainThreadIfPossible(completion, result: .failure(.notAvailable))
Expand Down
2 changes: 1 addition & 1 deletion Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ internal extension Purchases {
}

var offlineCustomerInfoEnabled: Bool {
return self.backend.offlineCustomerInfoEnabled
return self.backend.offlineCustomerInfoEnabled && self.systemInfo.supportsOfflineEntitlements
}

var publicKey: Signing.PublicKey? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,25 @@ class PurchasesConfiguringTests: BasePurchasesTests {
expect(Self.create(purchasesAreCompletedBy: .revenueCat).offlineCustomerInfoEnabled) == true
}

private static func create(purchasesAreCompletedBy: PurchasesAreCompletedBy) -> Purchases {
func testOfflineCustomerInfoDisabledForCustomEntitlementsComputation() throws {
try AvailabilityChecks.iOS15APIAvailableOrSkipTest()

expect(
Self.create(
purchasesAreCompletedBy: .revenueCat,
dangerousSettings: .init(customEntitlementComputation: true)
).offlineCustomerInfoEnabled
) == false
}

private static func create(
purchasesAreCompletedBy: PurchasesAreCompletedBy,
dangerousSettings: DangerousSettings = .init()
) -> Purchases {
return Purchases.configure(
with: .init(withAPIKey: "")
.with(purchasesAreCompletedBy: purchasesAreCompletedBy, storeKitVersion: .storeKit1)
.with(dangerousSettings: dangerousSettings)
)
}

Expand Down