Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rtuin
Last active July 15, 2018 21:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rtuin/7b1fe9b4bc325af92ec0 to your computer and use it in GitHub Desktop.
Save rtuin/7b1fe9b4bc325af92ec0 to your computer and use it in GitHub Desktop.
Titanium: Detect whether you're running in an emulator or not.
// Detect whether we're running inside a simulator or not.
// Put this in your app.js or alloy.js
function isEmulator() {
return (Ti.Platform.manufacturer == 'Genymotion' || Ti.Platform.model == 'Simulator');
}
// Use it to create mocks, for example:
function Foo() {
this.init();
}
if (!isEmulator()) {
Foo.prototype = _.extend(Backbone.Events, {
init: function() {
// do some device only stuff here
}
});
} else {
Foo.prototype = _.extend(Backbone.Events, {
init: function() {
// Mock the original Foo and it's methods.
}
});
}
module.exports = Foo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment