swift IAP按钮有回调吗?

yzxexxkh  于 2023-11-16  发布在  Swift
关注(0)|答案(1)|浏览(166)

我正在使用RevenueCat进行订阅。当我进行测试购买时,它工作正常,但我有一个奇怪的问题。我有一个单独的“购买”按钮,当按下时,RevenueCat操作表出现。
如果我按下右上角的小x按钮来关闭它,或者在actionSheet的外部按下,在Purchases.shared.purchase内部,.purchaseCancelledError会被调用。但是如果我按下蓝色的订阅按钮,然后按下警报的Ok,按钮,什么都不会发生。没有回调被触发,我不知道用户购买了订阅。
我如何知道用户何时点击订阅,然后从You're All Set警报中按下OK按钮?

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")
    }
}

字符串


的数据


tyky79it

tyky79it1#

不幸的是,苹果没有提供回调来知道“You're all set”对话框何时关闭。这是在操作系统级别控制的,所以即使是像RevenueCat这样的工具也无法控制它。

相关问题