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
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.