purchases-ios icon indicating copy to clipboard operation
purchases-ios copied to clipboard

iOS Swift RevenueCat Paywall delegate methods not being called.

Open anil72178 opened this issue 9 months ago • 7 comments

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")

}

}

anil72178 avatar Feb 28 '25 12:02 anil72178

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

RCGitBot avatar Feb 28 '25 12:02 RCGitBot

Hi @anil72178, Would you mind upgrading to the latest version of the SDK and see if the issue is resolved?

nyeu avatar Mar 04 '25 11:03 nyeu

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

EgorSigolaev avatar Apr 13 '25 12:04 EgorSigolaev

Try to remove this line
paywallVC.modalPresentationStyle = .fullScreen

Olegarh1 avatar May 16 '25 08:05 Olegarh1

Try to remove this line paywallVC.modalPresentationStyle = .fullScreen

But how to make paywall full screen, not like a sheet?

EgorSigolaev avatar May 16 '25 09:05 EgorSigolaev

Same issue here, using modalPresentationStyle = .fullScreen is required for me, though removing it didn't fix the problem anyway

zafarivaev avatar Jun 13 '25 18:06 zafarivaev

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)
}

zafarivaev avatar Jun 14 '25 11:06 zafarivaev

Issues resolved in latest version

anil72178 avatar Aug 30 '25 15:08 anil72178