Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8393733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:52:41+00:00 2026-06-09T19:52:41+00:00

BACKGROUND: I am running a phonegap app that I am building using phonegap build

  • 0

BACKGROUND:

I am running a phonegap app that I am building using phonegap build (1.6.1).

android build seems to work just fine,
however on iOS (Iphone 3GS 16M iOS: 5.0.1 (9A405) ) I never get the deviceready event.

I am trying to figure out what am I missing here.

QUESTIONS:
1. Does it matter if the binding of the deviceready event comes before or after including phonegap.js ?
2. Could it be that the event is happening “too early” and my handler is not yet bound to it ?
3. Is there a polling based way to figure out that the device is ready?
4. Where should handling of deviceready be done relating to JQuery’s $(document').ready ?

MY CODE:
my current code tries to synchronize 3 things:
1. JQuery’s .ready event
2. PhoneGap’s deviceready event
3. (careful) polling results on window.navigator.device.platform

in the following way:

<!DOCTYPE html>
<html>
<head>

    <script type="text/javascript" src="./scripts/jquery-1.7.2.js"></script>
    <script type="text/javascript" src="./scripts/jquery.myapp.js"></script>

    <script type="text/javascript">
        window.myapp={
            deviceReady:false,
            JQueryReady:false,
            started:false,
            logbuf:[]
        }

        function log(m){
            window.myapp.logbuf.push(m);
            console.debug(window.myapp.logbuf.join('||'));
            var  el=document.getElementById('container');
            if (el!=null) {
                el.innerHTML+=', ' + window.myapp.logbuf.join('||') ;
                window.myapp.logbuf=[];
            }
        }

        //Wait for device
        function onDeviceReady() {
            window.myapp.deviceReady=true;
            log('phonegap deviceready event fired');
            startIfAllReady();
        }
        document.addEventListener("deviceready", onDeviceReady, false);

        function pollDevice(){
            if (window && window.navigator && window.navigator.device && window.navigator.device.platform ) {
                log('polling found device');
                window.myapp.deviceReady=true;
                startIfAllReady();  
            }
            else {
                log('polling');
                window.setTimeout(arguments.callee,500);
            }
        }

        pollDevice();

        //Wait for jquery
        $(document).ready(
            function(){
                window.myapp.JQueryReady=true;
                log('jquery document.ready event fired');
                startIfAllReady();
            }
        );              


        function startIfAllReady(){
            log('startIfAllReady window.myapp.JQueryReady=' + window.myapp.JQueryReady + ' window.myapp.deviceReady=' + window.myapp.deviceReady + ' window.myapp.started=' + window.myapp.started );
            if (window.myapp.deviceReady && window.myapp.JQueryReady && window.myapp.started==false) {
                log('starting');
                started=true;
                renderClient();
            }
            else {
                log('cant start');                  
            }
        }

        function renderClient(){
            log('renderClient called - RETURNING !');
            return;
            window.setTimeout(function(){window.scrollTo(0, 1)},100);
            log('create myappClient');
            $('#myappClientContainer').empty().myappClient(
                {width:$(window).width(),
                 height:$(window).height()
                }
            );
        }

    </script>

    <script type="text/javascript" src="phonegap.js"></script>

    <link rel="stylesheet" type="text/css" href="./styles/client.css" />
    <style>
        html , body { margin:0px; background-color:gray;}
    </style>

    <title>myapp</title>
</script>
</head>
<body style="width:100%">

<script>
    log('body script executing');
</script>
<div style="width:100%" id="myappClientContainer">DEFAULT HTML</div>
</body>
</html>

CODE RESULTS:
in a regulat browser (chrome) I get:

DEFAULT HTML  
polling||body script executing||jquery document.ready event fired  
startIfAllReady window.myapp.JQueryReady=true window.myapp.deviceReady=false window.myapp.started=false   
cant start   
polling   
polling   
polling   
... (and polling....)  

on Iphone:

DEFAULT HTML  
polling||body script executing||jquery document.ready event fired  
startIfAllReady window.myapp.JQueryReady=true window.myapp.deviceReady=false window.myapp.started=false   
cant start

As you can see – no “phonegap deviceready event fired” anywhere, nor does the polling seem to work 🙁

notice that on the iphone, only single “polling” log entry at the start…
can’t iPhone handle onTimeout ?
why dont I get the deviceready event ?!

Another thing I noticed:
When (phonegap)building with debug set,
I can see the device/app in the PhoneGapBuild weinre debug window for some short time and then it just disappears.

Thanks

UPDATE:
my polling loop above is wrong,
It should look for window.navigator.platform

anyway I dropped it all together.
something Is just not working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:52:42+00:00Added an answer on June 9, 2026 at 7:52 pm

    seems like i neglected to update this Q.
    anyway the probelm was that ‘console.debug’ does not exist within winere and so my code was failing.

    Eyal

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed phonegap android app.I have been running the app in background when
Can I get a phonegap application running on iOS 4 to have a background
I am using GCD to start a long-running background process ('run_loop') that creates an
I have been working on an Android app using Phonegap and now would like
I have a TableModel that is populated from a background running thread. I am
I have a background thread running that fires events, but how can I ensure
My app is a background service running in the foreground. In low memory situations
I have an android recurring service running in background, no Activity running in front
Background : Running a PostgreSQL database for a Django app (Django 1.1.1, Python2.4, psycopg2
BACKGROUND: In running my app through a profiler, it looks like the hotspots are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.