At the moment I'm trying to include promoted products in my app with the help of RevenueCat. Unfortunately it does not work. (I am using SwiftUI 1.0, so still with AppDelegate.)
What I have done so far:
I have implemented the following function in AppDelegate as said here (https://docs.revenuecat.com/discuss/5cff570754c3420045b379f3):
func purchases(_ purchases: Purchases, shouldPurchasePromoProduct product: SKProduct, defermentBlock makeDeferredPurchase: @escaping RCDeferredPromotionalPurchaseBlock){
let defermentBlock = makeDeferredPurchase
}
Problem:
I think the problem is that I am running the defermentBlock in the wrong place. As it says here (https://sdk.revenuecat.com/ios/Protocols/RCPurchasesDelegate.html#/c:objc(pl)RCPurchasesDelegate(im)purchases:shouldPurchasePromoProduct:defermentBlock:), it should be called when the app is in the right state.
Currently I call the defermentBlock directly in the function like this:
func purchases(_ purchases: Purchases, shouldPurchasePromoProduct product: SKProduct, defermentBlock makeDeferredPurchase: @escaping RCDeferredPromotionalPurchaseBlock){
let defermentBlock = makeDeferredPurchase
// Should buy the product
defermentBlock { (transaction, info, error, cancelled) in
if let purchaserInfo = info {
Purchases.shared.purchaseProduct(product) { (transaction, purchaserInfo, error, userCancelled) in //this function works for products which are directly bought in the app
if error == nil && !userCancelled{
try? CoreDataManagerNew.shared.updateUserInformation()
}
}
}
}
}
Now I have the following questions:
- How do I cache the defermentBlock?
- When is the app in the right state? It opens automatically when I press the buy button in the AppStore.
Another problem is that I cannot test the functionality. The suggested way from Apple (https://developer.apple.com/documentation/storekit/in-app_purchase/testing_promoted_in-app_purchases) somehow does not work.
Many thanks in advance!