Hey Yosef,
You should be able to extract a specific package/product via the `packageWithIdentifier:` method on RCOffering.
So something like
// Accessing the monthly product
Purchases.shared.offerings { (offerings, error) in
if let offering = offerings?.current? {
if let package = offeringn"custom_package_id"] {
// This package should be 1:1 with a product on a single platform
}
}
}
now on the developer docs i found this code:
Purchases.shared.offerings { (offerings, error) in if let packages = offerings?.offering(identifier: "experiment_group").availablePackages { // Display packages for sale } }
if i understand correctly it allows me to fetch a specific offering.
With that above code, the packages
variable will be your array of RCPackage objects. Each RCPackage has an identifier you can filter out to grab a specific RCPackage by ID.
You may want to consider building your paywall off of the offering instead of individual packages, since pulling the package ID would requires hardcoding and doesn’t give you much flexibility if you want to change things remotely down the road. Offerings allow your paywall to be more dynamic, and display however many buttons/products you need based off the Offering. You can see an example of this in the sample app: https://github.com/RevenueCat/purchases-ios/blob/main/Examples/MagicWeather/MagicWeather/Sources/Controllers/PaywallViewController.swift#L54
Anyone has more info on this?
Hi Sharif :)
You are correct,
I am referring to the offerings and packages.
If i understand the setup correctly then:
1. every package has 1 product per platform
2. every offering can have multiple packages
What i want to accomplish is fetching a specific product for a specific button on my sales screen
(I will control the sales screen dynamically through my back end)
now on the developer docs i found this code:
Purchases.shared.offerings { (offerings, error) in if let packages = offerings?.offering(identifier: "experiment_group").availablePackages { // Display packages for sale } }
if i understand correctly it allows me to fetch a specific offering.
so if i want to fetch a specific product for a specific button on my sales screen
while using this code i’ll have to create a different offering for each product, correct?
My question is if there is a way to fetch a specific package within the offering since they have identifiers as well...
I’m assuming by package identifier you’re referring to our offerings and packages system that lets you group products together but if that’s not the case let me know and I’ll edit my answer to fit your question. You can get the product identifiers from within packages, but you have to unwrap the offering and package like this:
// Accessing the monthly product
Purchases.shared.offerings { (offerings, error) in
if let package = offerings?.current?.monthly?.product {
// Get the price and introductory period from the SKProduct
}
}
I included a Swift code sample above but you can find more code samples (Android included) in the section on getting the product from the package.
Similarly, you can use our GET /offerings endpoint to get a list of offerings server-side which you can unpack to get the package and product identifiers. A typical response returned by this endpoint looks like this:
{
"current_offering_id": "default",
"offerings": f
{
"description": "The default offering",
"identifier": "default",
"packages": a
{
"identifier": "$rc_monthly",
"platform_product_identifier": "monthly_free_trial"
},
{
"identifier": "consumable",
"platform_product_identifier": "consumable1"
},
{
"identifier": "$rc_annual",
"platform_product_identifier": "yearly_free_trial"
}
]
},
{
"description": "The sale offeringg",
"identifier": "sale_offering",
"packages": a
{
"identifier": "$rc_monthly",
"platform_product_identifier": "monthly_free_trial_sale"
},
{
"identifier": "consumable",
"platform_product_identifier": "consumable1_sale"
},
{
"identifier": "$rc_annual",
"platform_product_identifier": "yearly_free_trial_sale"
}
]
},
]
}