Virtual Currency Support
Description
This PR introduces virtual currencies to the iOS SDK. It's an exceptionally large PR, but all parts of it have been reviewed individually before.
It includes the following:
New APIs for Fetching Virtual Currency Balances + Metadata
New Top-Level Functions
These functions allow you to fetch the virtual currencies for the current subscriber. The invalidateVirtualCurrenciesCache function allows developers to clear the cached virtual currencies, which will then force the refreshing of the virtual currencies from the backend the next time virtualCurrencies() is called.
class Purchases {
@objc(virtualCurrenciesWithCompletion:)
func virtualCurrencies(
completion: @escaping @Sendable (VirtualCurrencies?, PublicError?) -> Void
)
func virtualCurrencies() async throws -> VirtualCurrencies
@objc
func invalidateVirtualCurrenciesCache()
}
New Objects
// A collection of virtual currencies returned by the backend
@objc(RCVirtualCurrencies) public final class VirtualCurrencies: NSObject {
/// Dictionary of all VirtualCurrency(``VirtualCurrency``) objects keyed by virtual currency code.
/// This dictionary can also be access through an index subscript on ``VirtualCurrencies``, e.g.
/// `virtualCurrencies["VC_CODE"]`.
@objc public let all: [String: VirtualCurrency]
}
@objc(RCVirtualCurrency)
public final class VirtualCurrency: NSObject {
@objc public let balance: Int
@objc public let name: String
@objc public let code: String
@objc public let serverDescription: String?
}
Example Usage
Swift:
let allVirtualCurrencies = try await purchases.virtualCurrencies().all
let gold = allVirtualCurrencies["GLD"]!
print("\(gold.name): \(gold.balance.description)"
Objective-C:
[p invalidateVirtualCurrenciesCache];
[purchases virtualCurrenciesWithCompletion: ^(RCVirtualCurrencies * _Nullable virtualCurrencies, NSError * _Nullable error) {
RCVirtualCurrency *gold = virtualCurrencies[@"GLD"];
NSLog(@"%@: %ld", gold.name, gold.balance);
}];
Virtual Currency Support in Customer Center
If developers enable it in the RevenueCat dashboard, their virtual currency balances can be displayed in the Customer Center. Currently, it displays the Virtual Currency's code and balance, but in a future PR we'll update this to include the name as well.
1 build increased size
| Name | Version | Download | Change | Install | Change | Approval |
|---|---|---|---|---|---|---|
| RevenueCat com.revenuecat.PaywallsTester |
1.0 (1) | 12.4 MB | ⬆️ 135.8 kB (1.11%) | 47.5 MB | ⬆️ 600.7 kB (1.29%) | N/A |
RevenueCat 1.0 (1)
com.revenuecat.PaywallsTester
⚖️ Compare build ⏱️ Analyze build performance
Total install size change: ⬆️ 600.7 kB (1.29%) Total download size change: ⬆️ 135.8 kB (1.11%)
Largest size changes
| Item | Install Size Change |
|---|---|
| DYLD.String Table | ⬆️ 246.3 kB |
| Code Signature | ⬆️ 14.9 kB |
| DYLD.Exports | ⬆️ 11.2 kB |
| 📝 RevenueCat.VirtualCurrencyManager.VirtualCurrencyManager | ⬆️ 4.1 kB |
| RevenueCat.DeviceCache.DeviceCache | ⬆️ 3.9 kB |
:flying_saucer: Powered by Emerge Tools
Comment trigger: Size diff threshold of 100.00kB exceeded
📸 Snapshot Test
18 added, 5 renamed, 211 unchanged
| Name | Added | Removed | Modified | Renamed | Unchanged | Errored | Approval |
|---|---|---|---|---|---|---|---|
| RevenueCat com.revenuecat.PaywallsTester |
18 | 0 | 0 | 5 | 211 | 0 | ✅ Approved |
:flying_saucer: Powered by Emerge Tools
| 1 Warning | |
|---|---|
| :warning: | This PR increases the size of the repo by more than 100.00 KB (increased by 246.47 KB). |
Generated by :no_entry_sign: Danger
@RCGitBot please test
@RCGitBot please test
@RCGitBot please test
