Last active
July 15, 2018 21:56
-
-
Save rtuin/7b1fe9b4bc325af92ec0 to your computer and use it in GitHub Desktop.
Titanium: Detect whether you're running in an emulator or not.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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