Detect sandbox IAP environment on device?

My macOS app offers non-renewing subscriptions which last for a month. This is long enough that if I change my system clock to test whether the app detects the expiration of the subscription correctly, StoreKit fails to obtain the products available for sale. I would like a way for my app to know it is in the sandbox so it may shorten the subscription durations in the sandbox only, similar to how auto-renewing subscriptions are handled automatically.


- These are non-renewing subscriptions, so the sandbox environment doesn't know how long they are supossed to last and can't change their duration automatically for testing as it does for auto-renewing subscriptions. (Despite the fact that AppReview literally called me on the phone and told me it does; there is no place in the appstoreconnect UI to add a duration for a non-renewing subscription.)

- I would like the method to work for AppReview as well, so merely doing a custom build which has the subscription duration shortened by build setting, environment variable or command line argument won't suffice.

- My users expect this app to work reliably without a reliable internet conneciton. It's already an imposition to ask them to get internet access for making purchases for renewals, but I need the app to know when a subscription has expired without internet access. Thus, I don't think I'm able to post to the store network endpoint that can directly tell me if it's sandbox.

Replies

I don't quite understand your needs.


In development you can set the code to cause a subscription to expire in one minute rather than in one month. Then change that just before you submit to the App Store. That works except if you want to allow App Review to test the expiration of a subscription - but why do you need/want to do that???? But suppose you did. Create a website and post something on that website that your app can access. During App Review, post "sandbox". After App Review approval post "Production". Then when your app first runs on a new install, test that website for "Sandbox" or "Production" and use that as a result for that app on that device. Note that during install your app will have access to the internet so your concern about internet access is irrelevant.

So, are you saying there is no way to make this determination on device?

I'm not sure about MacOS. You can send an iOS receipt associated with the app to the Apple production servers. They will respond with a 21007 error code if the receipt is generated in the sandbox.