iOS Swift RevenueCat Paywall delegate methods not being called.
I have the following code, but only the paywallViewControllerWasDismissed method is being called. Other PaywallViewControllerDelegate methods are not triggered. Any solution for this?
import Foundation import RevenueCatUI import RevenueCat import UIKit
class RevenueCatManager: NSObject {
static let shared = RevenueCatManager()
private override init() {}
func presentPaywall(from viewController: UIViewController, offeringID: String) {
Purchases.shared.getOfferings { (offerings, error) in
guard let offering = offerings?.offering(identifier: offeringID) else {
print("⚠️ Error fetching offering with ID: \(offeringID) - \(error?.localizedDescription ?? "Unknown error")")
return
}
DispatchQueue.main.async {
let paywallVC = PaywallViewController(offering: offering)
paywallVC.delegate = self
paywallVC.modalPresentationStyle = .fullScreen
viewController.present(paywallVC, animated: true)
}
}
}
}
extension RevenueCatManager: PaywallViewControllerDelegate {
func paywallViewController(_ controller: PaywallViewController, didFinishPurchasingWith customerInfo: CustomerInfo) {
print("✅ Purchase successful: \(customerInfo)")
}
func paywallViewControllerWasDismissed(_ controller: PaywallViewController) {
print("❌ Paywall was dismissed")
}
func paywallViewControllerDidStartPurchase(_ controller: PaywallViewController) {
print("⏳ Purchase process started")
}
func paywallViewControllerDidCancelPurchase(_ controller: PaywallViewController) {
print("⚠️ Purchase was canceled")
}
}
👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!
Hi @anil72178, Would you mind upgrading to the latest version of the SDK and see if the issue is resolved?
Hi! Did you solve the problem? I face the same issue. didFinishRestoringWith method is not called. didFailRestoringWith method is called, but shows it's own alert dialog. I can customize nothing. Is there anyone from support who can help me? I tested on revenuecat sdk version 5.21.1
Try to remove this line
paywallVC.modalPresentationStyle = .fullScreen
Try to remove this line paywallVC.modalPresentationStyle = .fullScreen
But how to make paywall full screen, not like a sheet?
Same issue here, using modalPresentationStyle = .fullScreen is required for me, though removing it didn't fix the problem anyway
Wrapping the SwiftUI PaywallView in a UIHostingController and presenting that controller resolved the issue. Callbacks are now arriving successfully, with the exception of onRestoreCompleted, which is only called if the user had an active subscription. If the user doesn't have a subscription, this callback is still not triggered. A pull request with a fix is already open: #5253.
struct RCPaywallView: View {
@ObservedObject private var viewModel: RCPaywallViewModel
init(viewModel: RCPaywallViewModel) {
self.viewModel = viewModel
}
var body: some View {
PaywallView()
.onPurchaseStarted { _ in
viewModel.performOnPurchaseStarted()
}
.onPurchaseCompleted { customerInfo in
viewModel.performOnPurchaseCompleted(customerInfo)
}
.onRestoreStarted {
viewModel.performOnRestoreStarted()
}
.onRestoreCompleted { customerInfo in
viewModel.performOnRestoreCompleted(customerInfo)
}
.onPurchaseFailure { error in
viewModel.performOnPurchaseFailure(error)
}
.onRequestedDismissal {
viewModel.performOnRequestedDismissal()
}
}
}
private func presentSwiftUIPaywall(viewModel: RCPaywallViewModel) {
let view = RCPaywallView(viewModel: viewModel)
let viewController = UIHostingController(rootView: view)
viewController.modalPresentationStyle = .fullScreen
sourceViewController.present(viewController, animated: true)
}
Issues resolved in latest version