How can an app detect which environment a push should be sent over / how should a server know whether to send pushes via production or sandox?

If a server is sending a push to an app, then how can it know whether it should be sending the push using the Apple sandbox push server, or the production server?

If the app is on the app store or testflight then it needs to be using the sandbox server, but if the app is being run via XCode interactively as devs are developing/testing then the push needs to be sent via the sandbox server.

But the server itself has no idea if the app was installed via Testflight/app store/XCode/ or a development .ipa. So the server can't know how to send the push.

The app has to send the push token to the server anyway, so the app could inform the server which environment it should be sent over. But then how can the app detect that itself?

A naive answer is to use #ifdef DEBUG to detect this, but that is incorrect. Which environment a push should be sent over is not correlated with that. For example an app could be being run with a debug scheme or a release scheme, but in both cases if the app is installed/running via xcode then the push environment has to be the sandbox.

So my question is, is there a way the app can detect which push environment a push should be sent over in order than it can instruct the server accordingly?

How can an app detect which environment a push should be sent over / how should a server know whether to send pushes via production or sandox?
 
 
Q