There are many details when it comes to testing IAP. This is a quick reference guide.
Sandbox & Production
Depending how you distribute and install, App Store can be using either the production or sandbox environment.
|How you distribute||App Store Environment|
|Build & run||Sandbox|
|App Store Release||Production|
It is obvious which environment will be used, except for TestFlight. This is because TestFlight is very much a production app – you are providing to external beta users, and should be using your own production environment.
The exception is App Store environment for TestFlight users. They will only connect to the sandbox, so that they will never need to pay real $.
Test Accounts for sandbox
You can create in App Store Connect > Users and Access > Sandbox Testers. You don’t need valid email.
On your device, sign in this test account in Settings app > App Store > Sandbox Account.
This sandbox user will NOT be used for TestFlight builds (but, I repeat, App Store will use the sandbox environment and users will not be charged).
Subscription Accelerated Rate on sandbox
On the App Store sandbox, subscription will renew at an accelerated rate. If not, our testing will literally take years.
|Production Duration||Sandbox Duration|
|3 days||2 minutes|
|1 week||3 minutes|
|1 month||5 minutes|
|2 months||10 minutes|
|3 months||15 minutes|
|6 months||30 minutes|
|1 year||1 hour|
Sandbox will also renew up to 6 times. So for a 1 year subscription, it can take around 6 hours to expire. So, go get your deserved sleep.
StoreKit Configuration File
This is new in 2020. We can set up in Xcode and test locally. This means using a local App Store environment (not sandbox).
A tedious step is that you have to create your products as this config file.
Enable in the scheme > Run > StoreKit Configuration.
When running on simulator, you can manage in Xcode > Debug > StoreKit.
A local environment can test many stuff.
What to test
- Purchase subscription
- Wait for subscription expiration
- Purchase one-time
- Delete app and restore purchase
These can only be tested on production:
- Cancel subscription
- Refund purchase