mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-10 22:45:55 +05:45
This was changed in #1460. Additionally, without #1600 this wasn't producing the correct rename, it wasn't finding `DeferredPromotionalPurchaseBlock` anywhere.
51 lines
1.6 KiB
Swift
51 lines
1.6 KiB
Swift
//
|
|
// PurchasesDelegateHandler.swift
|
|
// Magic Weather SwiftUI
|
|
//
|
|
// Created by Cody Kerns on 1/19/21.
|
|
//
|
|
|
|
import Foundation
|
|
import RevenueCat
|
|
|
|
/*
|
|
The class we'll use to publish CustomerInfo data to our Magic Weather app.
|
|
*/
|
|
|
|
class PurchasesDelegateHandler: NSObject, ObservableObject {
|
|
|
|
static let shared = PurchasesDelegateHandler()
|
|
|
|
}
|
|
|
|
extension PurchasesDelegateHandler: PurchasesDelegate {
|
|
|
|
/**
|
|
Whenever the `shared` instance of Purchases updates the CustomerInfo cache, this method will be called.
|
|
|
|
- Note: CustomerInfo is not pushed to each Purchases client, it has to be fetched.
|
|
This delegate method is only called when the SDK updates its cache after an app launch, purchase, restore, or fetch.
|
|
You still need to call `Purchases.shared.customerInfo` to fetch CustomerInfo regularly.
|
|
*/
|
|
func purchases(_ purchases: Purchases, receivedUpdated customerInfo: CustomerInfo) {
|
|
|
|
/// - Update our published customerInfo object
|
|
UserViewModel.shared.customerInfo = customerInfo
|
|
}
|
|
|
|
/**
|
|
- Note: this can be tested by opening a link like:
|
|
itms-services://?action=purchaseIntent&bundleId=<BUNDLE_ID>&productIdentifier=<SKPRODUCT_ID>
|
|
*/
|
|
func purchases(_ purchases: Purchases,
|
|
readyForPromotedProduct product: StoreProduct,
|
|
purchase startPurchase: @escaping StartPurchaseBlock) {
|
|
startPurchase { (transaction, info, error, cancelled) in
|
|
if let info = info, error == nil, !cancelled {
|
|
UserViewModel.shared.customerInfo = info
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|