How to distinguish Simulator from iPhone run

2 views
Skip to first unread message

Gabriel

unread,
Feb 27, 2010, 8:01:22 PM2/27/10
to EDUC 176 Programming Lab
Hey Steve and Troy,

My problem is thus: I would like to run the watchAcceleration() when I
am on the iPhone but NOT when I am running the app in the simulator.
When I try in the simulator, the app stops running for some reason I
can't discern. I tried doing:

if (typeof(PhoneGap) != 'undefined') {
alert("accel: "+ navigator.accelerometer.watchAcceleration);
return;
}

to no avail and I tried

if (navigator.accelerometer != null) {
}

but that doesn't work either. How can I tell [in Javascript] which
environment its running in?

Thanks,
Gabriel

Steve Marmon

unread,
Mar 1, 2010, 5:34:02 PM3/1/10
to EDUC 176 Programming Lab
Hi Gabriel,

Are you running your app inside of PhoneGap in the simulator, or just
as a regular webapp? The

if (typeof(PhoneGap) != 'undefined')

technique will work, but only if you use Mobile Safari to navigate
directly to your ~/sites/phonegap/iphone/www/index.html file.

- Steve

Gabriel Adauto

unread,
Mar 1, 2010, 8:33:49 PM3/1/10
to educ-176-pro...@googlegroups.com
We're on PhoneGap only.  Basically, when it's on the Simulator, you can't control the game, so there's no webapp-ability.  However, the Simulator loads way faster and is better for testing.

Thanks,
Gabriel
--
"...one must have a precise plan worked out for some reasonable period ahead. Allow me to inquire how man can control his own affairs when he is not only incapable of compiling a plan for some laughably short term, such as, say, a thousand years, but cannot even predict what will happen to him tomorrow?" - Master and Margarita, Mikhail Bulgakov
Reply all
Reply to author
Forward
0 new messages