Swift:未调用IAP updateTransactions.已购买 [英] Swift: IAP updatedTransactions not called on .Purchased

查看:77
本文介绍了Swift:未调用IAP updateTransactions.已购买的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有问题.购买交易时,函数updateTransactions仅被调用一次,而在交易完成后则不被调用.

I have a problem with my code. The function updatedTransactions is only called once while the transaction is .Purchasing and is not called after the transaction has ben completed.

func buyProduct(product: SKProduct) {
  let payment = SKPayment(product: product)
  SKPaymentQueue.defaultQueue().addTransactionObserver(self)
  SKPaymentQueue.defaultQueue().addPayment(payment)
}

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {

  for transaction in transactions {
    print(transaction)
    switch (transaction.transactionState) {
      case .Purchased, .Restored:
        print("Completed")
        complete(transaction)
        break
      case .Failed:
        fail(transaction)
        break
      default:
        break
    }
  }
}

推荐答案

对不起,我可能回答得有点晚,但这可能与

Sorry I might answer a bit late, but it might be related to this question. Are you testing your IAP from Xcode when it doesn't reach the .purchased state?

如果是,则需要将设备的App Store ID设置为您在iTunes Connect上创建的ID(用户菜单,沙箱测试器).

If yes, then you need to set your device's App Store ID to one you have created on iTunes Connect (User menu, Sandbox testers).

如果否,则可能是因为您的SKPaymentQueue已经包含太多等待完成的事务.您可以使用 SKPaymentQueue.default().transactions 进行检查.

If no, then maybe it could be because your SKPaymentQueue already contains too many transactions waiting to be finished. You can check it with SKPaymentQueue.default().transactions.

在我的情况下,我有28笔交易等待完成,因为在购买阶段,我的开关案例陈述不正确.

In my case I had 28 transactions waiting to be finished because I had a bad switch case statement during the purchase phase.

在这种情况下,您可以将这些行添加到 viewDidLoad 中以完成每一行(不要忘了删除找到它们的原因后再删除它们)):

If this is the case, you can add those lines in your viewDidLoad to finish each one of them (don't forget to remove them after you find why they didn't finish in your code):

for transaction: AnyObject in SKPaymentQueue.default().transactions {
    SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
}

这篇关于Swift:未调用IAP updateTransactions.已购买的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆