Skip to content

Commit

Permalink
Directly send delegate customer info when delegate is set (always sen…
Browse files Browse the repository at this point in the history
…ds cached CustomerInfo value) (#1828)

* Log delegate set before sending custoemr info

* Force call delegate with customer info when being set

* Committed wrong file

* Moved to own method and added comments
  • Loading branch information
joshdholtz authored Aug 15, 2022
1 parent 38f311b commit 5c15b5c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void
}

privateDelegate = newValue
customerInfoManager.sendCachedCustomerInfoIfAvailable(appUserID: appUserID)
Logger.debug(Strings.configure.delegate_set)

// Sends cached customer info (if exists) to delegate as latest
// customer info may have already been observed and sent by the monitor
sendCachedCustomerInfoToDelegateIfExists()
}
}

Expand Down Expand Up @@ -1724,6 +1727,18 @@ private extension Purchases {
}
}

// Used when delegate is being set
func sendCachedCustomerInfoToDelegateIfExists() {
guard let info = customerInfoManager.cachedCustomerInfo(appUserID: appUserID) else {
return
}

operationDispatcher.dispatchOnMainThread { [weak self] in
guard let self = self else { return }
self.delegate?.purchases?(self, receivedUpdated: info)
}
}

}

// MARK: - Deprecations
Expand Down

0 comments on commit 5c15b5c

Please sign in to comment.