Hi!
I'm working on my app that offers a "PRO" version with a monthly subscription, but i want to be ready to offer additional plans, like an annual version for example. To load the options, my view looks like this:
And i used it like this to generate the upgrade buttons.
Purchases.shared.getOfferings { (offerings, error) in
if let packages = offerings?.current?.availablePackages {
self.packages = packages
for package in self.packages {
let button = UIButton(type: .system)
let price = package.localizedPriceString
button.setTitle(price, for: .normal)
button.addTarget(self, action: #selector(self.ctaTapped(_:)), for: .touchUpInside)
button.tag = package.hash
self.CTAButtons.addArrangedSubview(button)
}
} else {
print("RevenueCat not working")
}
}
At the moment i only have one monthly subscription setup, but later it might have more options, like annual version. My first problem here is that how can i show the / month text on the button?(or /annual in case later i add another option). I don’t seem to find a way to get the billing cycle of the package.
Next, once the subscription is active, i want to show this view:
The problem here is pretty much the same, i’m not sure how to get the currently active subscription’s name, price and next renewal date. I did this:
Purchases.shared.getCustomerInfo { (customerInfo, error) in
if customerInfo?.entitlements.alll"pro"]?.isActive == true {
if let product_id = customerInfo?.entitlements.alll"pro"]?.productIdentifier {
Purchases.shared.getProducts(eproduct_id]) { products in
if let product = products.first {
self.subscriptionName.text = product.localizedTitle
self.subscriptionCost.text = product.localizedPriceString
if let expirationDate = customerInfo?.entitlements.alll"pro"]?.expirationDate {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .short
self.subscriptionRenewDate.text = "Renews: " + dateFormatter.string(from: expirationDate)
} else {
self.subscriptionRenewDate.text = ""
}
}
}
}
}
}
The only date i could find that was relevant is expirationDate, but i’m not sure thats the correct value to use in this case. There is “Period Type” in the entitlement, but based on the docs it have Trial, Intro and Normal as the value, not the actual billing period. Can you please point me in the right direction with this?
Thanks!