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

Logging: added log when configuring SDK in observer mode #2065

Merged
merged 2 commits into from
Nov 23, 2022
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/Logging/Strings/ConfigureStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ enum ConfigureStrings {

case store_kit_2_enabled

case observer_mode_enabled

case delegate_set

case purchase_instance_already_set
Expand Down Expand Up @@ -62,6 +64,8 @@ extension ConfigureStrings: CustomStringConvertible {
return "Debug logging enabled"
case .store_kit_2_enabled:
return "StoreKit 2 support enabled"
case .observer_mode_enabled:
return "Purchases is configured in observer mode"
case .delegate_set:
return "Delegate set"
case .purchase_instance_already_set:
Expand Down
2 changes: 2 additions & 0 deletions Sources/Misc/SystemInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class SystemInfo {
set { self._finishTransactions.value = newValue }
}

var observerMode: Bool { return !self.finishTransactions }

private let sandboxEnvironmentDetector: SandboxEnvironmentDetector
private let _finishTransactions: Atomic<Bool>

Expand Down
4 changes: 1 addition & 3 deletions Sources/Networking/HTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ private extension HTTPClient {
private extension HTTPClient {

var defaultHeaders: [String: String] {
let observerMode = !self.systemInfo.finishTransactions

var headers: [String: String] = [
"content-type": "application/json",
"X-Version": SystemInfo.frameworkVersion,
Expand All @@ -150,7 +148,7 @@ private extension HTTPClient {
"X-Client-Build-Version": SystemInfo.buildVersion,
"X-Client-Bundle-ID": SystemInfo.bundleIdentifier,
"X-StoreKit2-Setting": "\(self.systemInfo.storeKit2Setting.debugDescription)",
"X-Observer-Mode-Enabled": "\(observerMode)",
"X-Observer-Mode-Enabled": "\(self.systemInfo.observerMode)",
"X-Is-Sandbox": "\(self.systemInfo.isSandbox)"
]

Expand Down
3 changes: 3 additions & 0 deletions Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void
if systemInfo.storeKit2Setting == .enabledForCompatibleDevices {
Logger.info(Strings.configure.store_kit_2_enabled, fileName: nil)
}
if systemInfo.observerMode {
Logger.debug(Strings.configure.observer_mode_enabled, fileName: nil)
}
Logger.debug(Strings.configure.sdk_version(Self.frameworkVersion), fileName: nil)
Logger.debug(Strings.configure.bundle_id(SystemInfo.bundleIdentifier), fileName: nil)
Logger.user(Strings.configure.initial_app_user_id(isSet: appUserID != nil), fileName: nil)
Expand Down
9 changes: 5 additions & 4 deletions Sources/Purchasing/Purchases/PurchasesOrchestrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import StoreKit
final class PurchasesOrchestrator {

var finishTransactions: Bool { self.systemInfo.finishTransactions }
var observerMode: Bool { self.systemInfo.observerMode }

var allowSharingAppStoreAccount: Bool {
get { self._allowSharingAppStoreAccount.value ?? self.currentUserProvider.currentUserIsAnonymous }
set { self._allowSharingAppStoreAccount.value = newValue }
Expand Down Expand Up @@ -779,8 +781,7 @@ extension PurchasesOrchestrator: StoreKit2TransactionListenerDelegate {
}
}

// Need to restore if using observer mode (which is inverse of finishTransactions)
let isRestore = !self.systemInfo.finishTransactions
let isRestore = self.systemInfo.observerMode

_ = try await self.syncPurchases(receiptRefreshPolicy: .always,
isRestore: isRestore,
Expand Down Expand Up @@ -889,7 +890,7 @@ private extension PurchasesOrchestrator {
isRestore: allowSharingAppStoreAccount,
productData: productData,
presentedOfferingIdentifier: presentedOfferingID,
observerMode: !self.finishTransactions,
observerMode: self.observerMode,
initiationSource: initiationSource,
subscriberAttributes: unsyncedAttributes) { result in
self.handleReceiptPost(withTransaction: transaction,
Expand Down Expand Up @@ -1013,7 +1014,7 @@ private extension PurchasesOrchestrator {
isRestore: isRestore,
productData: nil,
presentedOfferingIdentifier: nil,
observerMode: !self.finishTransactions,
observerMode: self.observerMode,
initiationSource: initiationSource,
subscriberAttributes: unsyncedAttributes) { result in
self.handleReceiptPost(result: result,
Expand Down
2 changes: 2 additions & 0 deletions Tests/UnitTests/Misc/SystemInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ class SystemInfoTests: TestCase {
var systemInfo = try SystemInfo(platformInfo: nil,
finishTransactions: finishTransactions)
expect(systemInfo.finishTransactions) == finishTransactions
expect(systemInfo.observerMode) == !finishTransactions

finishTransactions = true

systemInfo = try SystemInfo(platformInfo: nil,
finishTransactions: finishTransactions)
expect(systemInfo.finishTransactions) == finishTransactions
expect(systemInfo.observerMode) == !finishTransactions
}

func testIsSandbox() throws {
Expand Down