deviceready not firing in iOS emulator

3,109 views
Skip to first unread message

Brill Pappin

unread,
Sep 11, 2011, 3:30:55 PM9/11/11
to phonegap
I can not get the deviceready event to fire in the iPhone 4 Emulator.

I'm using the Dreamweaver version, but I've also tried manually
updating to the latest download of phonegap just in case the
Dreamweaver version is out of date with no success.

No matter what i try, it is simply never called in the emulator.

I'm beginning to think that PhoneGap in the various emulators is
broken and am about to try publishing to a web server so I can call
the app from a physical device.

Does anyone else have experience with this problem?
A web search does not turn up any definitive solutions or reasons for
the problem (most requests of this nature go unanswered).

Brill Pappin

unread,
Sep 11, 2011, 4:54:42 PM9/11/11
to phon...@googlegroups.com
So, I've now tested this on a actual device with no results, deviceready simply refuses to execute.
I've even tried to re arrange the order the javascript is loaded to in order to make sure the correct code is loaded before the deviceready call.


Simon MacDonald

unread,
Sep 11, 2011, 5:20:35 PM9/11/11
to phon...@googlegroups.com

Show some code Brill.

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

Brill Pappin

unread,
Sep 11, 2011, 5:43:10 PM9/11/11
to phonegap
Which code? I've been through may iterations of code trying to get
this going. It's actually a pretty simple thing that's not working.

What i ended up with, which at least gets back to the code deviceready
would have called but is far from ideal, is:

<script type="text/javascript" charset="utf-8">
// PhoneGap is loaded and it is now safe to make calls PhoneGap
methods
//
var onDeviceReadyCallback = function() {
//alert("onDeviceReady called...");
// Now safe to use the PhoneGap API
listDirectory();
}

function onLoad() {
//alert("onLoad called...");

var state = document.readyState;
if (state == 'loaded' || state == 'complete') {
onDeviceReadyCallback();
} else {
if (navigator.userAgent.indexOf('Browzr') >
-1) {
setTimeout(run, 250);
} else {

document.addEventListener('deviceready',onDeviceReadyCallback,false);
}
}
}
</script>
(this is of course in the head section)

The deviceready event is not firing in Android or iOS emulators and
also not on a physical Android device (I haven't been able to test a
physical iOS device yet).

However, I've recently worked around it not firing (with the code
above) however I now get an error on a physical Android device (via
logcat):
Uncaught ReferenceError: DirectoryEntry is not defined at
file:///android_asset/www/index.html:97

This is starting to make me believe that the phonegap.js file is not
actually being loaded at all (which would explain the event not
getting fired).
This concerns me because the jquery-mobile files are getting loaded
just fine.

I'm about to resort to the Blackberry method of testing for a ready
device to see if I can generate any errors from phonegap (i.e. it's
not loaded and undefined).

Nimish Nayak

unread,
Sep 12, 2011, 1:09:28 AM9/12/11
to phon...@googlegroups.com
u might have made a minor mistake in the javascript file which u have included before this script.

Why dont you try with a sample index.html page from http://www.phonegap.com/start#android (As you mentioned android logcat so i am saying this).

and then take it ahead. 

Brill Pappin

unread,
Sep 12, 2011, 1:12:43 AM9/12/11
to phonegap
update:

Well I started from scratch in Eclipse and managed to get the
deviceready event to fire.
I have not dug too deep into the problem as I needed to actual get
some work done, but it may be that the path Dreamweaver was using (/
phonegap.js) was causing the issue. When I removed the slash prefix in
the Eclipse version, it seems to load. I have not gone back to check
the Dreamweaver code yet, but in case someone runs across this, try
futzing with the JS paths.

At this point I don't know why the event would not fire... this is
just my best guess without further investigation.

Nimish Nayak

unread,
Sep 12, 2011, 3:40:25 AM9/12/11
to phon...@googlegroups.com
Good to know you solved the issue. I dont work with Dreamweaver so i wont be able to conclude on your find.

But if possible and if you come across anything which could seem important to document please do so on www.phonegap.com under known issues 
(You might need to contact Shazron for this As i am not sure where one can document such user finds)

Jesse MacFadyen

unread,
Sep 12, 2011, 2:01:43 PM9/12/11
to phon...@googlegroups.com
If you open your index.html directly in Chrome, or Desktop Safari, and
turn on the developer tools you should be able to see where your error
is.
Unfortunately 1 error in JS can break everything, sometimes it is hard
to track down, especially if your app presents a UI without scripts
having run first.
This is usually my first step when something doesn't work. ie finding
a ':' instead of a ';' or other trivial typos that have disastrous
side effects

Cheers,
Jesse

--
--
Jesse MacFadyen
{
  blog:'blogs.nitobi.com/jesse',
  email:'jesse.m...@nitobi.com',
  company:
  {
    name:'Nitobi Software',
    site:'www.nitobi.com',
    phone:
    {
      office:'+1 (604) 685-9287',
      tollFree:'1-866-632-2777'
     }
  }
}

Sougata Pal.

unread,
Sep 12, 2011, 1:00:36 AM9/12/11
to phon...@googlegroups.com
Hello,

I have also faced the same problem for Symbian Emulator & Nokia E7 device.
--
Thanks
Sougata Pal.
Chief Architect, Techunits
http://in.linkedin.com/in/skallpaul
Contact: +91 9051042886

Andrew

unread,
Sep 11, 2011, 3:42:18 PM9/11/11
to phon...@googlegroups.com

I find that the 'deviceready' event sometimes fires before the listener is added (somehwhat dependant on the app). There is a way to check to see if the event has already been fired, but I can't remember what it is off the top of my head.

Reply all
Reply to author
Forward
0 new messages