Iphone – Error Domain=SKErrorDomain Code=2 “Cannot connect to iTunes Store” UserInfo=0x6083900 {NSLocalizedDescription=Cannot connect to iTunes Store}

iphonestorekit

I am trying to test my in app purchases using a test account. The first time I try to purchase an in app auto renewable subscription, everything goes smooth, no errors and the transaction is complete as expected with the transaction state updated to "SKPaymentTransactionStatePurchased". But, when I test for the scenario of a user trying to purchase the subscription again, I keep getting the above error. Even though the store kit framework displays a dialog saying that the user is already subscribed, my observer sees the transaction as failed in the state(SKPaymentTransactionStateFailed).

The storekit documentation clearly says
"If the user attempts to purchase a nonconsumable product or a renewable subscription they have already purchased, your application receives a regular transaction for that item, not a restore transaction. However, the user is not charged again for that product. Your application should treat these transactions identically to those of the original transaction".
In my case here, I keep getting the transaction state as "failed" when I do the purchase again.

Any ideas? This is in the sandbox test environment.

Best Answer

This is the expected behavior. You still receive a transaction, it just marks it in a failed state because it does not represent a new, successful purchase. Repurchasing a subscription they already subscribe to (presumably to restore a purchase after a fresh install) is not a journey you should encourage your users to take, they should be directed towards the restore purchases function.

Arguably you might want to interrogate your failed purchases every time to see if this is what the user was trying to do, but then you'd have to do a fair amount of messing around to try and distinguish which ones were genuine failures and which one's were erroneous restores. but I'd say it's much easier to have a big 'restore' button and direct people towards that.

Related Topic