getCustomerInfo
Gets the latest CustomerInfo asynchronously.
This method was introduced in version 4.10.0. It provides an async way to get the latest customer information.
Purpose
Retrieves the latest CustomerInfo asynchronously. If customer info is already available, it returns immediately. Otherwise, it waits for the first non-placeholder customer info to be loaded. In SDK 4.19.1 and later, if configuration fails or the waiting task is cancelled, it returns the current customerInfo instead of waiting indefinitely. That value may be empty when purchases have not loaded.
This method returns the available customer info; it does not force a server refresh. Use refreshCustomerInfo() when your server has just reported a purchase.
Signature
public func getCustomerInfo() async -> CustomerInfo
public func getCustomerInfo(completion: @escaping (CustomerInfo) -> Void)Parameters
No parameters for the async version. The completion handler version takes a completion closure.
Returns / State
Returns a CustomerInfo object containing the latest customer purchase and subscription data.
Usage
Using async/await:
let customerInfo = await Superwall.shared.getCustomerInfo()
// Use the customer info
print("User has \(customerInfo.subscriptions.count) subscriptions")
print("Active product IDs: \(customerInfo.activeSubscriptionProductIds)")Using completion handler:
Superwall.shared.getCustomerInfo { customerInfo in
// Handle customer info
print("User has \(customerInfo.subscriptions.count) subscriptions")
// Update UI on main thread
DispatchQueue.main.async {
self.updatePurchaseHistory(customerInfo)
}
}In a Task:
Task {
let customerInfo = await Superwall.shared.getCustomerInfo()
// Process customer info
await processCustomerInfo(customerInfo)
}Related
-
refreshCustomerInfo()- Fetch current entitlements from Superwall (4.19.0+) -
customerInfo- Published property for customer info -
customerInfoStream- AsyncStream of customer info changes -
customerInfoDidChange(from:to:)- Delegate method for customer info changes
How is this guide?