Skip to content


[Titanium] How to detect if an application is running in simulator

Testing for a virtual device can be useful for a variety of features not or poorly working in those, for instance push notifications (last time I tried it just seemed to block the execution) or the camera (as mentioned in this post, on a virtual device you could replace the camera with a “fake” one by loading a picture from the disk).

The Ti.Platform.model variable should contain all you need to determine whether or not you’re running on a real device. On the iOS simulator it will return “Simulator”, on an Android emulator it will return something like “google_sdk”. So a way to test for it would be simply:

if (Ti.Platform.model === 'Simulator'
 || Ti.Platform.model.indexOf('sdk') !== -1 ){
    alert('This is a virtual device');
}

(sorry for the poor indentation, WordPress makes it pretty tough :s)

Sources:
https://developer.appcelerator.com/question/63871/way-to-detect-running-in-simulator
http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Platform-property-model

Posted in programming.

Tagged with .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.

Sorry about the CAPTCHA that requires JS. If you really don't want to enable JS and still want to comment, you can send me your comment via e-mail and I'll post it for you.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA