Solved

How can I implement Promoted in-app purchase?

  • 30 July 2021
  • 1 reply
  • 695 views

Badge +2

Hi there,

I’ve been searching for a few days how to implement promoted in-app purchases in my app with RevenueCat. 

My environment:

  • RevenueCat SDK version is 3.12.2
  • iOS platform
  • iOS 14
  • Xcode 12.5.1

Research

Question

Now, SwiftUI apps launch using a custom struct that conforms to the App protocol, so there is no AppDelegate file anymore. My App struct is something like that:

@main
struct SimoleonApp: App {

init() {
Purchases.configure(withAPIKey: "KEY")
}

var body: some Scene {
WindowGroup {
ContentView()
}
}
}

My question is, where do I have to place the following function to support promoted in-app purchases?

func purchases(_ purchases: Purchases, shouldPurchasePromoProduct product: SKProduct, defermentBlock makeDeferredPurchase: @escaping RCDeferredPromotionalPurchaseBlock) {
makeDeferredPurchase { (transaction, info, error, cancelled) in
if let purchaserInfo = info {
handlePurchaserInfo()
}
}
}

Thank you.

icon

Best answer by tina 2 August 2021, 18:22

View original

1 reply

Userlevel 5
Badge +10

This issue was resolved in a ticket, pasting reply below:

To implement the shouldPurchasePromoProduct delegate you would need to conform to PurchasesDelegate somewhere and set the delegate on Purchased. Example: 

class AnyClass: NSObject, PurchasesDelegate {
func purchases(_ purchases: Purchases, shouldPurchasePromoProduct product: SKProduct, defermentBlock makeDeferredPurchase: @escaping RCDeferredPromotionalPurchaseBlock) { }
}
Purchases.shared.delegate = AnyClass()

AnyClass can be any class/object that you have where you want to handle it. For SwiftUI, maybe in one of your view model classes. It's typically in the AppDelegate, but the SwiftUI app lifecycle does not have that by default. 

Feel free to add any additional information that helped you solved this!

Reply