我正在尝试实施自动更新订阅产品。问题是SKPaymentQueue
不能通过SKPaymentTransaction
调用完成SKPaymentQueue.defaultQueue().finishTransaction(transaction)
。
func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
if let transactions = transactions as? [SKPaymentTransaction] {
for transaction in transactions {
switch transaction.transactionState {
case .Purchasing:
break
case .Purchased:
queue.finishTransaction(transaction) // finish transaction
self.purchasedWithTranasction(transaction)
case .Failed:
queue.finishTransaction(transaction) // finish transaction
self.failedWithTransaction(transaction)
case .Restored:
queue.finishTransaction(transaction) // finish transaction
self.restoredWithTransaction(transaction)
case .Deferred:
queue.finishTransaction(transaction) // finish transaction
}
}
}
}
如上所述,InpaymentQueue:updatedTransactions:
方法queue.finishTransaction(transaction)
被调用。通常,交易已完成,不会再停留。
但是当我再次运行该应用程序时,该交易仍未完成。顺便说一句,我在 AppDelegate 中设置了事务观察器,如下所示。因此,当应用程序启动时,剩余的事务开始通过调用来处理paymentQueue:updatedTransactions:
。这不像我的预期。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// add transaction observer
SKPaymentQueue.defaultQueue().addTransactionObserver(CargoBay.sharedManager())
....
return true
}
你们对这个问题有任何想法吗?有SKPaymentQueue.defaultQueue().finishTransaction(transaction)
没有没有完成交易的案例?