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?

AFAIK the only way to get the environment in which the app is running is by parsing the embedded provisioning profile inside the app and retrieve the value for aps-environment, but its format is proprietary and subject to change.

It is my understanding that the proper way to do is to try and send the notification on the production environment by default and fallback on the development environment if that fails. I have yet to find a confirmation for this but if we take a successful notification service like firebase that does not ask for an environment value, I don’t see how else they’d do it.

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