Skip to main content
Question

Having trouble initiating payment UI for monthly subscription


Forum|alt.badge.img+1
I am trying to implement a monthly subscription as part of an in-app purchase.
 I am using a combination of xcode/swift and RevenueCat to implement this feature. In implementing the code that runs when the user clicks the purchase button i get the error saying "Fatal error: NSArray element failed to match the Swift Array Element type
Expected Package but found RCPackage". 

Where the code for the purchase button click is highlighted. Code is "guard let package = offerings.all.first?.value.availablePackages.first ".

I am not sure what to do to fix this issue.

 

 

2 replies

sharif
RevenueCat Staff
Forum|alt.badge.img+9
  • RevenueCat Staff
  • 513 replies
  • May 7, 2022

Sorry for the delay! Are you still seeing this issue? I’m not sure why Xcode is giving you that error. I just tried your code snippet and included a print, and the code ran and printed successfully:

What happens if you use [0] instead of .first? So instead of this:

guard let package = offerings.all.first?.value.availablePackages.first

Try this:

guard let package = offerings.all.first?.value.availablePackages[0]

I tried this on version 4.3.0 of the SDK using Xcode 13.3.1.

Here’s the code snippet I used so you can easily copy and paste to rule out any syntax errors:

Show content
Purchases.shared.offerings { offerings, error in
            guard let offerings = offerings, error == nil else {
                return
            }
            guard let package = offerings.all.first?.value.availablePackages.first else {
                return
            }
            print(package.identifier)
        }

 

 


Forum|alt.badge.img

You need to remove the revenucat pod file from your code, they have conflicts with   pod 'Purchases' and the  pod Revenucat.

just delete the   pod Revenucat. from code after that it will work. 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings