【发布时间】:2019-07-24 05:18:31
【问题描述】:
我有两个自动续订订阅,每月和每年 (iOS)。当我使用新的沙盒用户时,我可以进行购买。虽然我必须输入密码三次。流程如下:
- 点击订阅
- 输入密码
- 提示再次输入密码
- 出现“无法连接到 iTunes Store”错误
- 再试一次并输入密码
- 购买成功。
继续前进,一旦成功,我现在就订阅了,并且我的 UI 会通过 appDelegate 中的侦听器更新,该侦听器会发布我订阅的通知。但是当我尝试从每月切换到每年订阅时,反之亦然,它总是给我“无法连接到 iTunes Store”错误。没有用户界面更新。流程如下:
- 点击其他订阅
- 提示输入 iTunes 密码
- 收到“确认购买”对话框,说明我正在修改订阅
- 点击继续
- 收到“一切就绪”成功提醒。
- 解除警报
- 收到“无法连接到 iTunes Store”错误
- 没有调用我的监听器,没有更新 UI,等等。
但是,如果我消除错误并再次点击订阅,我会收到一条警报,指出我已经订阅了该计划,即使引发了错误并且我的听众没有收到更改。
我正在使用火力基地。我遵循了 RevenueCat 文档中的快速入门和 Firebase 特定说明。我所有的调试日志似乎都很好,没有非 200 状态,没有无效的产品 ID。下面是一些sn-ps的代码:
AppDelegate:
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")
}
})
}
【问题讨论】:
标签: ios swift in-app-purchase revenuecat