我有两个自动续订订阅,每月和每年(iOS)。我可以在使用新的沙盒用户时进行购买。虽然我必须输入三次密码。这是流程:
继续,所以一旦成功,我现在订阅,我的UI通过appDelegate中的监听器更新,该监听器发布我订阅的通知。但是当我尝试切换订阅时,从每月切换到每年,反之亦然,它总是给我“无法连接到iTunes Store”错误。没有UI更新。这是流程:
但是如果我解除错误并再次点击订阅,我会收到一条警告,说我已经订阅了该计划,即使错误被抛出而且我的收听者没有收到更改。
我正在使用firebase。我按照RevenueCat文档中的快速入门和Firebase特定说明进行操作。我的所有调试日志似乎都很好,没有非200状态,没有无效的产品ID。以下是一些代码段:
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")
}
})
}
这就是为所有SKErrors抛出的通用NSError消息。错误代码2是“付款已取消”。但是,这也是您已订阅项目时抛出的错误。
在您尝试重新订阅之前,您确定要让年度订阅到期吗?通过年度订阅,他们将在到期前每小时更新6次。
要查看特定的SKError,您将执行以下操作:
if let error = error as? SKError {
print("SKError - ")
switch error.code { // https://developer.apple.com/reference/storekit/skerror.code
case .unknown:
print("unknown error")
case .paymentCancelled:
print("cancelled error")
case .clientInvalid:
print("client invalid")
case .paymentInvalid:
print("payment invalid")
case .paymentNotAllowed:
print("payment not allowed")
case .cloudServiceNetworkConnectionFailed:
print("cloud service network connection failed")
case .cloudServicePermissionDenied:
print("cloud service permission denied")
case .storeProductNotAvailable:
print("store product not available")
case .cloudServiceRevoked:
print("cloud service revoked")
}
}
一旦你知道正在返回的SKError,我可以根据需要更新我的答案,并提供有关可能发生的事情的更多信息。