R – stuck with sandbox account

app-store-connectin-app-purchaseiphonesandbox

I created a test account to check in app purchases. I could purchase and the purchase was successful. After that I found a bug in navigation. I fixed a bug, created another account and deleted the account I logged in in previous session. Now I cannot test the in app purchases anymore, since the app store log me in automatically with a ghost account that already doesn't exists. I'm asked to enter a password only in spite that before each debug session I sign out from the Store in Settings and delete the previous version of the application. How do I reset this?

Thanks,

Nava

Best Answer

I know this is an old topic, but I had trouble finding a solution and went through some mind-numbing trial and error until I figured out a solution so I thought I would share it here since I was unable to find it anywhere else.

First, make sure after every transaction you call:

    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

What happened in my case is that a transaction wasn't finished and stayed on the queue so even when I switched to a different sandboxed account it still continued to ask for my old account's password.

To fix it I added:

SKPaymentQueue *queue = [SKPaymentQueue defaultQueue];
for (SKPaymentTransaction *transaction in queue.transactions) {
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

BEFORE I added the transaction observer, ie this:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

Also, in the

(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions

function, I added this line of code:

[queue finishTransaction:transaction];

in the SKPaymentTransactionStateRestored and SKPaymentTransactionStateFailed cases of the switch statement. Don't add it to the purchased state because you aren't allowed to call finish on that from what I know.

I'm not sure which of the two above steps fixed the bug because it persisted until I signed out of my iPhone, deleted the app, powered it down, and did a clean rebuild/install that it finally stopped asking me for the password to the bugged account. Hope this helps someone.

EDIT: (11/12/15)

So I found out the cause of breaking sandbox accounts. It happened after restoring purchases, then hitting the home key, reopening and hitting the restore button again which caused a crash. The restore stayed in the queue and the above process was the only way to get out of the popups asking for the password.

In order to stop that, I added:

[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

to by tearDown function (called by applicationDidEnterBackground:) of my main view controller before I nil'd my in-app purchase manager object. I think what was happening is that I added the object as a transaction observer more than once and it was causing the odd behavior. From the looks of it, this seems to have fixed the problem entirely because I haven't been able to recreate the error again.

Related Topic