Sir Code-A-lot
Sir Code-A-lot

Reputation: 153

PhoneGap Deviceready won't fire on first run of app (iOS)

I'm having a weird issue with my app.

It's a multi page phone gap app that users jQuery (not jQuery mobile).

When you first run the app after installing it, it will fire device ready on the index page.

After moving to the other pages the deviceready will not fire again.

if i close the app and start it again every thing works fine and device ready is fired on every page.

so to summarise: deviceready won't fire on FIRST RUN OF APP (after installing) on pages other then the index.

Also, none of my phonegap plugins work either on first run.

What changes after the first run of the app? this is so weird...

Ver: PhoneGap 2.9.0.

Upvotes: 0

Views: 479

Answers (2)

Sir Code-A-lot
Sir Code-A-lot

Reputation: 153

Ok, eventually I learned that PhoneGap and multiple pages don't play very well together. so I wrote the whole damn thing all over again in a single page and using jquery mobile only for page ajax caching. at the end result i got better transitions and a faster app :).

So my tip is: if you're just starting to code a phonegap app. use a one-page structure, it will save you a lot of debugging time. also i would not recommend using jquery mobile's features too much, just stick to the page transitions and use the regular jquery for the rest.

Hope this helped someone :)

Upvotes: 0

Andrew Lively
Andrew Lively

Reputation: 2153

The deviceready event will only fire once when you launch the application. If you are returning from the background then you have to listen for the resume.

When you are switching between those pages after the app has launched then you could do something like .ready() to handle when the specific page is loaded, like this:

$(document).ready(function() {
    // Do your stuff here
});

You can read more on PhoneGap events here.

Upvotes: 1

Related Questions