Is it possible for an iOS app to programmatically detect if its built for TestFlight/App Store distribution versus built for development?
The motivation for doing this is so that the app can detect if a push server should send pushes using the Apple production server or the sandbox server - when the app sends the push token to the server, I'd like it to additionally send an indicator to the server so the server knows which of the Apple servers to use.
Is there a way to achieve this?
TIA
Argun and I have been chatting about this behind the scenes.
Right.
The answer here varies by platform:
-
On macOS you can do this using the code signing API.
-
That API is not available on iOS, or any of its child platforms, so there isn’t a good way to achieve this goal there.
IMPORTANT I’ve seen folks use a variety of unsupported techniques for this on iOS. The reason why I’ve seen this is that those techniques tend to be brittle, and they ask for help when their code breaks )-: I recommend that you not go down that path.
With the advent of the LightweightCodeRequirements framework we are very close to being able to support this sort of thing on iOS. You can build a requirement without any problems, you just can’t check it (because routines like SecTaskValidateForRequirement
are macOS only). I think it’s well worth you filing an enhancement request for an iOS API that let’s a process check a requirement against itself.
Please post your bug number, just for the record.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"