Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Way to detect running in simulator?

I'm looking for ways either to detect I'm running in the simulator, or have some different build configuration so that I can have my application use a different URL for the web service it contacts. Typical case is, when I'm doing development, I want the app to talk to the web server running on my local machine. But, when I setup the app for Ad Hoc testing on iPhone, and distribute to phones, etc. I want it to use a public web server.

What are some solutions for this kind of thing?

— asked September 22nd 2010 by Christopher Bailey
  • simulator
0 Comments

2 Answers

  • Accepted Answer

    Try something like this…..

    if (Titanium.Platform.model == 'google_sdk' || Titanium.Platform.model == 'Simulator') {
    //Whatever is unique to simulator
    }

    — answered September 22nd 2010 by Mike Robinson
    permalink
    2 Comments
    • Thanks, that's working great!

      — commented September 23rd 2010 by Christopher Bailey
    • Genymotion emulator get output:

      Google Nexus 4 - 4.2.2 - API 17 - 768x1280

      or something similar.

      — commented May 16th 2014 by Andrey Tkachenko
  • Watch out : with SDK 1.8, Titanium.Platform.model does not return "Simulator" anymore in iOS, but "x86_64" for instance.

    Here is what I've got :
    [INFO] model = x86_64
    [INFO] name = iPhone OS
    [INFO] version = 5.0
    [INFO] ostype = 32bit
    [INFO] osname = ipad

    — answered November 17th 2011 by Henri-Maxime Ducoulombier
    permalink
    1 Comment
    • I confirmed this, and regardless of device I am getting osname= iPad.

      — commented November 23rd 2011 by Juan Bermudez
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.