我有两个自动续订订阅,每月和每年 (iOS)。当我使用新的沙盒用户时,我可以进行购买。虽然我必须输入密码三次。这是流程:
- 点击订阅
- 输入密码
- 提示再次输入密码
- 收到“无法连接到 iTunes Store”错误
- 重试并输入密码
- 购买成功。
继续前进,一旦成功,我现在就订阅了,并且我的 UI 会通过 appDelegate 中的侦听器更新,该侦听器会发布我订阅的通知。但是当我尝试从每月切换到每年订阅时,反之亦然,它总是给我“无法连接到 iTunes Store”错误。没有用户界面更新。这是流程:
- 点击另一个订阅
- 提示输入 iTunes 密码
- 收到“确认购买”对话框,说明我正在修改我的订阅
- 点击继续
- 收到“一切就绪”成功警报。
- 解除警报
- 收到“无法连接到 iTunes Store”错误
- 没有调用我的听众,没有更新 UI,等等。
但是,如果我消除错误并再次点击订阅,我会收到一条警报,说我已经订阅了该计划,即使抛出了错误并且我的听众没有收到更改。
我正在使用火力基地。我遵循了 RevenueCat 文档中的快速入门和 Firebase 特定说明。我所有的调试日志似乎都很好,没有非 200 状态,没有无效的产品 ID。以下是一些代码片段:
应用委托:
Purchases.debugLogsEnabled = true
Purchases.configure(withAPIKey: Constants.revenueCatKey)
Purchases.shared.delegate = self
FirebaseApp.configure()
authHandle = Auth.auth().addStateDidChangeListener() { (auth, user) in
if let uid = user?.uid {
Purchases.shared.identify(uid, { (info, error) in
if let e = error {
print("sign in error: \(e.localizedDescription)")
} else {
print("User \(uid) signed in")
}
})
}
...
}
}
extension AppDelegate: PurchasesDelegate {
func purchases(_ purchases: Purchases, didReceiveUpdated purchaserInfo: PurchaserInfo) {
if self.currentUser != nil {
if purchaserInfo.activeSubscriptions.contains(Constants.audiomeshSubscriptions.monthly) {
guard let myRef = DataService.instance.REF_PRIVATE else { return }
myRef.updateData(["plan" : "paidMonthly"]) { err in
if let err = err {
print("error updating user-private with new subscription: \(err)")
} else {
NotificationCenter.default.post(name: Notification.Name(rawValue: "purchaserInfoUpdated"), object: nil)
}
}
}
else if purchaserInfo.activeSubscriptions.contains(Constants.audiomeshSubscriptions.yearly) {
//do the same for yearly subscription
}
else {
//handle non-paying users here
}
}
}
}
UpgradeController(购买 UI):
@objc func purchaseButtonSelected(sender: AudiomeshButton) {
let buttonTag = sender.tag
guard let option = options?[buttonTag] else { return }
let product:SKProduct = option.product
Purchases.shared.makePurchase(product, { (transaction, purchaserInfo, error) in
if let error = error {
print("error making purchase: \(error)")
} else {
print("Purchase Successful")
}
})
}