Testing In-App Purchase on iPhone - ios

I have setup my app to use In-App Purchases. All the necessary steps have been done and everything works except for one thing, the final step for completing the purchase transaction i.e. SKPaymentTransactionState always completes with Failed every time.
So I did some research and found another post that said not to test this in the simulator and do it on a physical device as it seems there is a limitation placed on making purchases in the simulator by Apple on purpose.
So I went back to try to run this on my physical iPhone instead. The problem I'm having now is that my physical iPhone is linked to my active iTunes account. When I try to make a purchase on it, the User ID is already defaulting to my active ID and it only asks for my password.
So my question is (1) How do I force the phone to ask for me to enter a new User ID and Password so that I can use the Sandbox User I created in iTunes Connect? (2) I am a little nervous about even entering a secondary iTunes credentials, can anyone validate what the behavior is like? I do not want my active iTunes account to have any issues, it is possible to run both my active iTunes account and the sandbox user on my physical device with no issues?

Log out of iTunes on the phone via Settings, but wait for the app to prompt you to log in before entering your sandbox account credentials. NOTE that I'm referring to iTunes, not iCloud. It gets more interesting if you need to do that.
When you're done testing, log out again via Settings but differently than before, go ahead and re-log in via Settings to your "regular" Apple ID to return to production use.
You can't run them "simultaneously" as such but you can use your regular device to sandbox test without problems.

Related

Devices with iOS 15 ignore my sandbox account during test in-app purchases

We have recently updated several test devices from iOS 14.7.1 to 15.2. After that, when trying to make a test purchase inside our app, TestFlight ignores the sandbox accounts (which we add to Settings -> Apps-Store -> Sandbox account) and uses the main account that is used for purchases in the App Store.
The SandBox account works fine if you log out as the main user in the App Store - but then you can't use TestFlight to download test builds.
maybe someone has faced a similar problem and knows the solution or will tell me in which direction to look?
TestFlight ignores the sandbox accounts (which we add to Settings -> Apps-Store -> Sandbox account) and uses the main account
That is correct behavior. The sandbox account is for when you are running an Xcode build. TestFlight, on the other hand, always uses your real account, but it doesn't charge you (and the same for your beta testers).
#matt is right. The only what I can add here is that after you
logged in as sandbox user > attached device to xcode > run the build > made the purchase with sandbox user
you will be able to use that sandbox user even in next TestFlight builds.
For other testers this new approach is very uncomfortable, expecially if tester has a very complex password for their primary accounts... Apple made these things worst, for sure.
Btw, important to note that making purchases using primary account in sandbox environment (liek your testers do in TestFlight builds) will also reset the subscriptions in some time range. Not sure what exactly, probably from 5min to 1h. I didn't know it and had tons of questions, why my app doesn't recognise any previous subscription made recently. Purchase restore response also says that there is nothing to restore... Weird way of tasting, Apple...

How to verify if an iOS sandbox account is valid still?

I'm having some issues with sandbox users. According to Apple's docs
Important: If you mistakenly use a sandbox tester account to sign in to a production environment, like iTunes, on your test device instead of your test environment, the sandbox account becomes invalid and can’t be used again. If this happens, create a new sandbox tester account with a new email address.
In my case I haven't tried to login to the production environment with these accounts, but am still getting the invalidated somehow. It seems they will be good for a day or two, and for the first couple purchases and then stop working.
I'm getting back SKErrorDomain Code: 0 NSLocalizedDescription: Cannot connect to iTunes Storemost times when I try to purchase.
Most recently I even got "You are not authorized to make purchases of this InApp Purchase in Sandbox at this time. [Environment: Sandbox]"
I'm very flustered by these errors because it seems that it will work fine and then intermittently stop working. Has anyone found a way to successfully verify if an account is invalid, or found a way to get past these issues?
Each time I run into this problem, these steps typically clear it:
Make sure phone is signed out of all services (iCloud, App Store, everything)
Restart the phone.
Remove the app from phone and re-install via Xcode
When the app prompts for credentials during in-app purchase, enter sandbox credentials.
There is the very off chance that the sandbox account must accept some new terms from Apple. Log-into developer.apple.com and make sure you don't have any lingering alerts for that account.
Best of luck!

Apple sandbox user logout before production

I developed a Phonegap iOS app that implements In app purchase. As suggested here, I used a sandbox user in order to test the IAP during the development process in iOS, but i can not find a way to switch back to my personal account to authenticate the application.
At the start of the development process, i signed out with my personal account, i didn't login with my sandbox user in General > iTunes & App Store, i started the application and i logged in with my sandbox user from that.
It is time now to pass to production and i can not figure out how to logout the sand box user from my app. If i start the application a Sign In popup is displayed and the sandbox email is there. It simply ask for the password but now chance to change the account. When i login within the application the sandbox user account is logged in General > iTunes & App Store, but if i log out from there the application is stuck with the sandbox email. In other words, it is like if the app is now linked to that email account and it does not give me the chance to change it.
I tried to remove the application (tapping on it and pressing the X button and from General > Manage storage), install it again, to soft reset the iPhone, log out from iTunes & App Store, rebuild the application in debug mode or not, including the plugin or not, in many combination but with no success.
Does anybody experienced something like this? How did you logout your sandbox user when you switched back to your personal iTunes Connect account?
I'm not sure how it looks like on previous iOS versions, but on iOS 12.0 you can open:
Settings > Your Name (Apple ID, iCloud & App Store) > iTunes & App Store
There you will find a section called "SANDBOX ACCOUNT" where you can sign out of the sandbox account you've been using.
On iOS 14 & 15:
Go to Settings > App Store
Scroll down until the end and you'll find the title "SANDBOX ACCOUNT", there you'll see the sandbox account you are currently logged in to, tap over it and it will let you change it.
I have found 2 ways to avoid the problem but first be sure to use a "fresh" testing account.
Change the Bundle Identifier in Xcode and iTunes Connect
Restore the iPhone
I go for the first one because my Testing device is also my personal iPhone and I can't afford restoring every week.
I spent so much time on that so I hope my answer can help you.

Can not log into sandbox by test account on iOS

I am implementing in app purchases for my app. I am logged out from AppStore, created some test accounts, have not verify it by e-mail.
And every time I tried to log in into sandbox app-purchase I got an transaction error. Btw product info restored correctly.
Looking deeply I notice that after any attempt to log in, my AppStore account setting in device filled with the info from this test account! So I think it tries to log in into real AppStore instead of sandbox.
What am I doing wrong? Why my test accounts tries to login into the real AppStore and how to fix it?
To know if you're in sandbox environment or not, you can have a look at the purchase popup. If you can read "[Sandbox environment]" at the bottom, then it means you're using the sandbox. Otherwise, you're using the real Appstore (But I'm pretty sure it's not the case since this is automatically chosen by the device).
Anyway, it seems that Apple Sansbox environment is experiencing some problems today.
For example, I have an app that was dealing correctly with inapp purchase yesterday. Today, only retrieving SKProducts was ok.
I recommend you to be patient until the problem is fixed by Apple.

iOS in app purchase - "this account does not have permission.."

Ok here goes trying to explain this as clearly as possible:)
I have developed an app for a partner.
They wanted to submit the app under their company so I was given the certs and profiles. I packaged the app ...they submitted and all was fine.
Now I need to update the app with new content. So all this is done and the client has set up new in App purchase products for the app.
The Problem:
When I am testing all of the "product requests" are successful and it displays the description of the product etc.
However when I come to test purchasing with a iTunes test account it does not work. It says
"This account doesn't have permission to make in app purchases. You
can change account permissions in iTunes Connect."
However to try and work out the problem, as a test I quickly set up a "test" app in OUR iTunes account and a new bundle id etc and set up same IAP products. I then changed the app ID for the actual client app to point at this. And this works fine no problem what soever when testing via Xcode on device.
I am at a loss at what is wrong here as when I did the original app all worked as expected as in I was able to use a iTunes test account I had set up to test their app.
Any ideas what might be going on?
regards
ade
Apparently the test user account needs to be on the same apple developer account as your app!

Resources