Skoua
Skoua

Reputation: 3603

SKPaymentTransaction always fail

I'm building an app with Swift and I just added StoreKit support. There is only consumable products in my app.

AppDelegate follows the SKPaymentTransactionObserver protocol and here's my paymentQueue:updatedTransactions method:

func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {
    for transaction in transactions as [SKPaymentTransaction] {
        switch transaction.transactionState {
            case SKPaymentTransactionState.Purchasing:
                println("purchasing")

            case SKPaymentTransactionState.Purchased:
                println("payment done")
                SKPaymentQueue.defaultQueue().finishTransaction(transaction)

            case SKPaymentTransactionState.Failed:
                println("payment failed")
                SKPaymentQueue.defaultQueue().finishTransaction(transaction)

            default:
                println("nop \(transaction.transactionState)")
        }
    }
}

I've created a test user in iTunes connect and so on and everything works fine except all transactions failed whatever I do.

Transactions go to purchasing state and then failed, even if I confirm the transaction in simulator.

Any idea why this happening?

Thanks.

Upvotes: 1

Views: 3418

Answers (3)

dminones
dminones

Reputation: 2296

As @w0mbat says the hole flow is working now except for the actual confirm transaction, in order to manage this you can do the following

Import target conditionals header

#include "TargetConditionals.h"

Modify your failed transaction method

- (void)failedTransaction:(SKPaymentTransaction *)transaction
   {
        if (TARGET_IPHONE_SIMULATOR  && DEBUG && (transaction.error.code==0))
        {
            [self completeTransaction:transaction];
            return;
        }
        ...
   }

Upvotes: 0

anil72178
anil72178

Reputation: 67

You Can Test IAP in Your ios6.1 Simulator and yes iOS 8.0 Simulator Also Gives You Response Alert But DoesNot Provide Purchase Functionality In Simulator

Upvotes: 1

w0mbat
w0mbat

Reputation: 2459

The official word from Apple is that StoreKit doesn't work in the simulator.

These days, with an iOS 8 target in the current simulator quite a lot of it does work, like fetching the list of products, or putting up the purchase confirmation dialog. However the final purchase still fails in the simulator, and that appears to be deliberate on Apple's part.

Upvotes: 8

Related Questions