我正在测试我的应用程序自动续订订阅,但SKPaymentTransaction.transactionState
从未更改为.purchased
并且始终为.restored
. 一切正常,但.restored
自从我第一次打电话以来,我什么也得不到SKPaymentQueue.default().restoreCompletedTransactions()
。我尝试从我的 iPhone 中删除该应用程序,重新登录到我的沙盒帐户,创建一个新的沙盒帐户,重新启动 Xcode,清理构建文件夹,......我做错了什么?请在下面找到我的代码:
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
switch transaction.transactionState {
case .purchased:
SKPaymentQueue.default().finishTransaction(transaction)
print(".purchased")
case .failed:
SKPaymentQueue.default().finishTransaction(transaction)
print(".failed")
case .restored:
SKPaymentQueue.default().finishTransaction(transaction)
print(".restored")
default:
break
}
}
}
@IBAction func restore(_ sender: UIBarButtonItem) {
SKPaymentQueue.default().restoreCompletedTransactions()
}
func subscribe() {
if SKPaymentQueue.canMakePayments() {
let payment = SKPayment(product: availableProducts[indexPath.row])
SKPaymentQueue.default().add(payment)
}
}
override func viewDidLoad() {
super.viewDidLoad()
SKPaymentQueue.default().add(self)
}