我正在使用 RevenueCat 进行订阅。当我进行测试购买时它工作正常,但我遇到了一个奇怪的问题。我有一个单独的“购买”按钮,按下时会出现 RevenueCat 操作表。
如果我按右上角的小 x 按钮将其关闭,或者按 actionSheet 外部的
Purchases.shared.purchase
内部,.purchaseCancelledError
会被调用。但是,如果我按蓝色的“订阅”按钮,然后按警报的“确定”按钮,则不会发生任何情况。没有触发回调,我不知道用户购买了订阅。
我如何知道用户何时点击“订阅”,然后按下“全部设置”警报中的“确定”按钮?
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")
}
}
不幸的是,Apple 没有提供回调来了解“一切就绪”对话框何时关闭。这是在操作系统级别控制的,因此即使像 RevenueCat 这样的工具也无法对其进行任何控制。