I've been having this problem and I'm convinced its a bug. I've filed a bug report with Bug Id 10108270
The problem seems to be that the test user is getting 'locked' and may have something to do with attempting to purchase an in app purchase in an already released app with that account.
My workaround was to create a new test user but until Apple get back to me, I can't provide any better solutions. I'll update this answer when I get replies.
I'm hitting the same issue. For me it happens after this secuence:
Install app on a device logged into a UK account on iTunes
Launch the app and use a test user set in USA
Message is shown saying account is only valid in USA. Closes the app and auto launches iTunes
Open your app again and retry purchase. Receive products but no other callback or error.
I don't know whether this is an issue on the IAP platform but I would like to get an error/callback to handle it in some way in my code.
To carry on testing your IAPs try any of these:
Remove Provisioning Profile in Settings area, remove App and log out from Store in Settings. Then go to XCode and change the signing identities to "Do Not Sign" to then put them back (I know how it sounds :) but try) OR
Hard reset all Settings on your device (Settings -> General...). Obviously you will loose any settings on that device...
Kill iTunes app on the device (multitask menu) and log out from the Store on the Settings
If none of the above work, it might be an issue on IAP platform, see my comments below.
Make sure you have signed out of any production iTunes accounts on the device.
I was getting this error on my test phone which was logged in with my actual iTunes account. You cannot test apps using your production iTunes account, hence the error. I just wish Apple provided a better error so as to avoid this guesswork...
This is an old thread that is related to problem I was facing today.
In my case, I was able to test in-app purchases on my device till yesterday but it stopped working today. It turned out that Apple had pushed an 'Amendment for Paid Applications' for me to review and agree to. Once I agreed to the amendment (without reading it, of course), everything started working again. Did not have to create a new test user or any other workaround.
There may be many reasons for in-app purchases to not work but make sure you are correctly set up on itunesconnect or you won't be able to test in-app purchases.
For newcomers, make sure your in-app purchasing product's status is Ready to Submit, with no "missing metadata". In my case, what was missing was the localization of the subscription's group.
You may also be getting this error when reusing an old sandbox account you tested a previous IAP on another app with (My scenario). Apple really needs to update the way we test IAPs, I'm running out of emails :0
I was able to purchase in-app on iPhone but not on iPad(11.0.2). I tried with all mentioned solution but none helps. After trying all other possibilities, finally I was able to make it work.
When you create a test account in iTunes connect, don't verify the email id. If it is verified, iap returns "Cannot connect to iTunes" error. It looks strange but it is how worked for me. In iPhone, irrespective of email verification, I am able to purchase using test account.
Check that your app does have a bundle version (CFBundleVersion)
Check that the product is available for sale. Did you create it in App Store Connect?
If previous iOS 12, signed out of any production iTunes accounts on the device. Otherwise, you can just sign in within the dev app with your sandbox account.
The same issue got for me, and I had checked on the issue including Apple form, I couldn't find a solution.
Today when I checking the device I found that the following
In Device Settings -> iTunes & App Store found another Apple Id logged In.
So I tried signOut that and checked again the InApp purchase, it worked perfectly. So please check the issue is linked to the same or not.
In addition to all the other methods outlined here, if you are working with subscriptions it seems you need to make sure you've generated a shared secret:
"To test or offer auto-renewable subscriptions, you must have a master shared secret or use an app-specific shared secret for each app."
A master shared secret is generated from the 'Shared Secret' tab of the 'Users and Access' section of App Store Connect.
An app-specific shared secret is generated where you manage the in-app purchases of the app itself.
I fixed mine! If you are getting Error Domain=SKErrorDomain Code=2 "Cannot connect to iTunes Store" error, make sure you insert SKPaymentQueue.default().finishTransaction(transaction). It worked for me after I added SKPaymentQueue.default().finishTransaction(trans) in the following:
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for trans in transactions{
if trans.transactionState == .purchased {
print("Successful.")
SKPaymentQueue.default().finishTransaction(trans)
} else if trans.transactionState == .failed {
print("failed!")
print(trans.error)
SKPaymentQueue.default().finishTransaction(trans)
}
}