Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKPaymentQueue does not finish SKPaymentTransaction for an auto-renewable subscription product

I'm trying to implement Auto-renewable subscription product. The problem is that SKPaymentQueue cannot finish SKPaymentTransaction by calling 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
            }
        }
    }
}

As the above, In paymentQueue:updatedTransactions: method, queue.finishTransaction(transaction) are called. Normally, the transactions are finished and will not stay anymore.

But when I run the app again, that transactions still remain not finished. By the way, I set the transaction observer in the AppDelegate like the below. So, when the app launched, remaining transactions start being processed by calling paymentQueue:updatedTransactions:. It's not like my expectation.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // add transaction observer
    SKPaymentQueue.defaultQueue().addTransactionObserver(CargoBay.sharedManager())

    ....

    return true
}

Do you guys have any idea about this problem? Is there any case that SKPaymentQueue.defaultQueue().finishTransaction(transaction) does not finish transaction?

like image 871
Mike Avatar asked Oct 29 '22 22:10

Mike


1 Answers

Is it possible that you're not seeing the same transaction again, but instead a new auto-renewal transaction from the iTunes sandbox?

When testing auto-renewing subscriptions in the iTunes sandbox, they artificially speed up the rate of renewals. This causes a new transaction to appear every few minutes.

From Testing Your App and In-App Purchase Products:

When testing auto-renewable subscriptions in the test environment, keep in mind that the duration times are compressed. Additionally, test subscriptions only auto-renew a maximum of six times.

  • 1 week : 3 minutes
  • 1 month : 5 minutes
  • 2 months : 10 minutes
  • 3 months : 15 minutes
  • 6 months : 30 minutes
  • 1 year : 1 hour
like image 155
gmcnaughton Avatar answered Nov 15 '22 08:11

gmcnaughton