Skip to content

Commit

Permalink
Paywall Tester: fix automatic dismissing after purchasing
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Dec 13, 2023
1 parent 32c63cd commit 99d605a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct AppContentView: View {
#if !os(watchOS)
private func presentPaywallViewController() {
let paywall = PaywallViewController(displayCloseButton: true)
paywall.delegate = paywallDelegate
paywall.modalPresentationStyle = .pageSheet

guard let rootController = UIApplication
Expand All @@ -176,6 +177,8 @@ struct AppContentView: View {

}

// MARK: -

private struct ProminentButton: View {

var title: String
Expand Down Expand Up @@ -224,6 +227,23 @@ extension CustomerInfo {

}

// MARK: - Delegate

private let paywallDelegate = PaywallDelegate()

private final class PaywallDelegate: NSObject, PaywallViewControllerDelegate {

func paywallViewController(
_ controller: PaywallViewController,
didFinishPurchasingWith customerInfo: CustomerInfo
) {
controller.dismiss(animated: true)
}

}

// MARK: -

#if !os(watchOS)

private extension UIApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ struct OfferingsList: View {
}
.sheet(item: self.$presentedPaywall) { paywall in
PaywallPresenter(offering: paywall.offering, mode: paywall.mode)
.onPurchaseCompleted { _ in
self.presentedPaywall = nil
}
}
}

Expand Down

0 comments on commit 99d605a

Please sign in to comment.