Reputation: 39
Right now I'm building an app in the Meteor JS framework -- an app that can run both from a browser as well as be packaged with Cordova Phonegap for iOS / Android use.
I would like to be able to detect if I am in Cordova or not. I still want to distinguish between mobile browser and mobile PhoneGap usage.
Detect between a mobile browser or a PhoneGap application doesn't make sense for me as I am still loading the Meteor app via an HTTP call.
How else could I detect if the user is loading our app from PhoneGap or not?
Upvotes: 1
Views: 992
Reputation: 3282
Today it's much easier:
if (Meteor.isCordova) {
console.log("Printed only in mobile cordova apps");
}
Meteor Docs: Adding Cordova/Phonegap-specific Javascript code
Upvotes: 3
Reputation: 75945
Well you could always check up if the deviceready handlers get initiated and use a session hash to store this e.g
document.addEventListener("deviceready", function() {
Session.set("isphonegap",true);
}, false);
You can use this reactively e.g
Deps.autorun() {
if(Session.equals("isphonegap", true)) {
//Yes its phonegap!
}
}
The only thing is you have to assume its always not phonegap, and if deviceready
fires (on a device within phonegap/cordova) then you can check with Session.get("isphonegap")
whether the device is using phonegap in your template helpers or anywhere else reactive variables can run
Upvotes: 1