I wonder if System.getDeviceSettings().uniqueIdentifier is constant and unique for each installed simulator. Or is there already another solution except conditional compiling?
How about the previously-mentioned placeholder app idea (for CIQ 3.2 or higher)?
- Create a placeholder app with a known UUID that you will never install the store
- "Install" the placeholder app in the…
And that's what most of us use, but it's not 100%
It's good for not releasing accidentally some thing not meant for release.
But sometimes you do want (or need to) run release build in the simulator. Although in most of those cases you probably would want to run release (non-emulator) code anyways (i.e DataField on old device with not enough memory or trying to recreate a crash from ERA)
Then you could set a storage value in debug mode. Which in theory only gets set in Simulator. Then if you subsequently run release in Simulator it can work in same manner. Like you say depends on needs. You just need a system works for 99% of time, and can be quickly tweaked for those 1% or less of cases.
It's pretty unlikely that battery and batteryInDays would line up exactly at 50.0 and exactly at 5.0 particularly often, but I agree it's not perfect; sadly that seems to be the way of things given the absence of any official way of having such an obviously useful bit of functionality. (And anyway it's the kind of thing you would annotate with (:debug), so you wouldn't be at risk of publishing it in production.)
How about the previously-mentioned placeholder app idea (for CIQ 3.2 or higher)?
- Create a placeholder app with a known UUID that you will never install the store
- "Install" the placeholder app in the sim by building and running it
- In your real apps, call System.isAppInstalled() with the placeholder app's UUID. If isAppInstalled returns true, the app is running in the simulator
The nice thing about this is the UUID of the placeholder app stays the same forever, so the simulator detection code in your real apps never has to change.
Other than lack of support for pre-CIQ 3.2 devices, the biggest downside I can think of is that if you delete all apps from the sim, you have to reinstall the placeholder app. Perhaps you could try to get around that by setting permissions in the filesystem to prevent the placeholder app PRG from being deleted.
This method has the advantage that it seems impossible for it to ever generate false positives (i.e. it will never tell an app that it's running in the sim when it isn't, unless you accidentally publish the placeholder app to the store *and* somebody installs the placeholder app to their device).
Yeah, I guess that is a solution, but if you're going down that kind of route it seems a rather complicated way of doing it. You may as well just achieve the same thing using a storage variable, which you manually set once in the simulator using Edit Application.Storage Data and otherwise provide no user accessible means of setting it to true. i.e. something like:
var IS_SIMULATOR as Lang.Boolean = false; private function calledAtStartup() as Lang.Void { var isSimulatorNullable = Storage.getValue(activityKey("isSimulator")); IS_SIMULATOR = isSimulatorNullable != null ? isSimulatorNullable as Lang.Boolean : false; Storage.setValue(activityKey("isSimulator"), IS_SIMULATOR); }
Wastes 4 bytes of storage space I guess.