目前,我正试图在 RevenueCat 的帮助下将促销产品包含在我的应用程序中。不幸的是,它不起作用。(我使用的是 SwiftUI 1.0,所以仍然使用 AppDelegate。)
到目前为止我做了什么:
我已经在 AppDelegate 中实现了以下功能,如此处所述(https://docs.revenuecat.com/discuss/5cff570754c3420045b379f3):
func purchases(_ purchases: Purchases, shouldPurchasePromoProduct product: SKProduct, defermentBlock makeDeferredPurchase: @escaping RCDeferredPromotionalPurchaseBlock){
let defermentBlock = makeDeferredPurchase
}
问题:
我认为问题在于我在错误的地方运行 defermentBlock。正如这里所说(https://sdk.revenuecat.com/ios/Protocols/RCPurchasesDelegate.html#/c:objc(pl)RCPurchasesDelegate(im)purchases:shouldPurchasePromoProduct:defermentBlock:),应该在应用程序运行时调用它在正确的状态。
目前我直接在函数中调用 defermentBlock,如下所示:
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()
}
}
}
}
}
现在我有以下问题:
- 如何缓存 defermentBlock?
- 应用程序何时处于正确状态?当我在 AppStore 中按下购买按钮时,它会自动打开。
另一个问题是我无法测试功能。Apple(https://developer.apple.com/documentation/storekit/in-app_purchase/testing_promoted_in-app_purchases)建议的方式不起作用。
提前谢谢了!