iosswiftin-app-purchaserevenuecat

Do IAP buttons have callbacks?


I'm using RevenueCat for subscriptions. It works fine when I make the test purchase but I'm having an odd problem. I have a separate "Purchase" button, when pressed, the RevenueCat action sheet appears.

If I press the little x button in the right hand corner to dismiss it or press outside of the actionSheet, inside Purchases.shared.purchase, .purchaseCancelledError gets called. However if I press the blue Subscription button, and then press the alert's Ok, button, nothing happens. No callbacks get triggered and I have no idea that the user purchased a subscription.

How can I know when the user hits the Subscribe then pressed the OK button from the You're All Set alert?

func purchaseButtonTapped() {

    let productID = "..."

    Purchases.shared.getOfferings { [weak self](offerings, error) in
        guard let _ = error else { return }

        for dict in offerings.all {
                
            let offering = dict.value
            let packages = offering.availablePackages
                
            if let indexOfItem = packages.firstIndex(where: { $0.storeProduct.productIdentifier == productID }) {
                    
                let pkg = packages[indexOfItem]
                    
                self?.showSystemActionSheet(for: pkg)
                break
            }
        }
    }
}

func showSystemActionSheet() {

    Purchases.shared.purchase(package: package) { (transaction, customerInfo, error, userCancelled) in

        if let error = error as? RevenueCat.ErrorCode {
            switch error {
            case .purchaseCancelledError: // *** using breakpoints this gets hit when I cancel or dismiss the actionSheet
                return
            case .productAlreadyPurchasedError, .operationAlreadyInProgressForProductError, .receiptInUseByOtherSubscriberError :
                print("purchase is active")
            case .purchaseNotAllowedError:
                print("purchases_not_allowed")
            case .purchaseInvalidError:
                print("invalid_purchase_check_payment_method")
            default: break
            }
            return
        }

        if userCancelled {
            return 
        }

        guard let customerInfo = customerInfo else { 
            return 
        }

        // after the user pressed Subscribe then pressed the OK button from the You're All Set alert, this print statement should get print/get hit with a break point but it never does
        print("the subscribe button and You're All Set alert was tapped")
    }
}

enter image description here

enter image description here


Solution

  • Unfortunately, there is no callback provided by Apple to know when the "You're all set" dialog is dismissed. This is controlled at the OS level so even tools like RevenueCat don't have any control over it.