Advertisement
ampsonic

revenuecat paywall

Jul 7th, 2025
396
0
13 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.82 KB | None | 0 0
  1. private func loadOffering() {
  2.         Purchases.shared.getOfferings { (offerings, error) in
  3.             print("DEBUG: === RevenueCat Offerings Debug ===")
  4.            
  5.             if let error = error {
  6.                 print("DEBUG: Error loading offerings: \(error.localizedDescription)")
  7.                 return
  8.             }
  9.            
  10.             guard let availableOfferings = offerings else {
  11.                 print("DEBUG: No offerings returned")
  12.                 return
  13.             }
  14.            
  15.             print("DEBUG: Available offerings count: \(availableOfferings.all.count)")
  16.             print("DEBUG: Available offering identifiers: \(Array(availableOfferings.all.keys))")
  17.             print("DEBUG: Current offering identifier: \(availableOfferings.current?.identifier ?? "none")")
  18.            
  19.             if let newPaywallOffering = availableOfferings["newPaywall"] {
  20.                 print("DEBUG: Found newPaywall offering!")
  21.                 print("DEBUG: newPaywall offering identifier: \(newPaywallOffering.identifier)")
  22.                 print("DEBUG: newPaywall packages count: \(newPaywallOffering.availablePackages.count)")
  23.                
  24.                 // Check if packages exist
  25.                 for package in newPaywallOffering.availablePackages {
  26.                     print("DEBUG: Package: \(package.identifier) - \(package.storeProduct.localizedTitle)")
  27.                 }
  28.                
  29.                 self.offering = newPaywallOffering
  30.             } else {
  31.                 print("DEBUG: newPaywall offering NOT found")
  32.                 // Fallback to current offering
  33.                 if let currentOffering = availableOfferings.current {
  34.                     print("DEBUG: Using current offering as fallback: \(currentOffering.identifier)")
  35.                     self.offering = currentOffering
  36.                 }
  37.             }
  38.            
  39.             print("DEBUG: === End RevenueCat Debug ===")
  40.         }
  41.     }
  42.  
  43.     public var body: some View {
  44.         Group {
  45.             if let offering = offering {
  46.                 PaywallView(offering: offering, displayCloseButton: true)
  47.                     .onPurchaseCompleted { customerInfo in
  48.                         onPurchaseCompleted(customerInfo)
  49.                     }
  50.                     .onPurchaseCancelled {
  51.                         onCanceled?()
  52.                     }
  53.             } else {
  54.                 // Loading state while fetching offerings
  55.                 VStack {
  56.                     ProgressView()
  57.                         .scaleEffect(1.5)
  58.                     Text("Loading...")
  59.                         .padding(.top)
  60.                         .foregroundStyle(.secondary)
  61.                 }
  62.             }
  63.         }
  64.         .captureViewActivity(as: "InAppPurchaseView")
  65.         .onAppear {
  66.             loadOffering()
  67.         }
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement