I have a RevenueCat implementation that is working but I don't like the flow and am struggling with improving it. I know there has to be a more refined way to do this, so any help would be appreciated:
@IBAction func btnMnthlyPressed(_ sender: Any) {
Purchases.shared.offerings { (offerings, error) in
if let e = error {
print(e.localizedDescription)
}
guard let offering = offerings?.current else {
print("No current offering configured")
return
}
for package in offering.availablePackages {
print(package.identifier)
if package.identifier == "$rc_monthly" {
Purchases.shared.purchasePackage(package) { (transaction, info, error, cancelled) in
if cancelled {
print("User cancelled purchase")
return
}
// Optionally handle specific purchase errors
if info?.entitlements.all["FullAccess"]?.isActive == true {
print("Unlocked Pro Cats ")
}
}
}
print("Product: \(package.product.localizedDescription), price: \(package.localizedPriceString)")
}
}
}
Maybe I'm trying to do too much in the func...