This is a migrated thread and some comments may be shown as answers.

First start on Icenium ION call twice "onDeviceReady" on iOS

6 Answers 50 Views
AppBuilder companion app
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andres
Top achievements
Rank 1
Andres asked on 07 Jun 2013, 10:19 AM
Hi,
i got no troubles deploying to Android (simple apk file).

In the app i populate the database at first start, something like:
document.addEventListener("deviceready", onDeviceReady, false);
var app = {};
app.db = null;
// PhoneGap is ready
function onDeviceReady() {
    navigator.splashscreen.hide();
    // Database 
     populateDatabase();   
  }

So, the app running on Icenium ION never populated the DB. so i just "debugged" like:
function populateDatabase() {    
    var localstg = localStorage.getItem("firstStart");
   alert("Value of localstg " + localstg"); --> should be null
if (localstg == null) {
localstg = localStorage.setItem("firstStart", true);
 alert("localstg " + localstg); --> true
}

}

So what i can see when i start the app in the icenium ION is both alert windows.

Hope you understand what i mean. I didnt try with IOS provisioning.







      
}

6 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 07 Jun 2013, 03:08 PM
Hello Andres,

Your code would always fire an alert and would fire a second alert if the localStorage is null (which according to your comment is). This does not mean that the deviceready Cordova event is fired twice. Can you elaborate if your problem is different, please elaborate what is the expected behavior and let us know which is your app, so we can take a look at it.

Regards,
Steve
Telerik

Looking for tips & tricks directly from the Icenium team? Check out our blog!
Missed our first webinar, watch it here.
Share feedback and vote for features on our Feedback Portal.
0
Andres
Top achievements
Rank 1
answered on 07 Jun 2013, 03:26 PM
Hi Steve,

sorry, i write incorrectly the code

function populateDatabase() {    
var localstg = localStorage.getItem("firstStart");
   alert("Value of localstg " + localstg"); --> should be null. I see the alert at first start
if (localstg == null) {
app. createTable();
app.insertData(); 
localstg = localStorage.setItem("firstStart", true);
 alert("localstg in IF " + localstg); --> true
}

first, i see:  ("Value of localstg"  null)

The data is never being populated, but i see the alert ("local stg in IF" => true) (inside the if Sentence). i did this because i didnt know if was better to use "null" or "undefined".
app.insertData(): call to a ajax loader that i never see.

And then i see again the alert ("Value of localstg"  true).

In Android or simulator the first start works fine:

1. Alert local STG: null
2. Ajax loading (database populated). Alert: true

Hope i explained correctly.


0
Andres
Top achievements
Rank 1
answered on 07 Jun 2013, 08:52 PM
Hi again.

Once i installed the app in icenium ION, i saw that SQL Lite functions didnt work (i got no error!).

I changed the localStorage item (to be able to just add database at first load).

After i refreshed the app, the SQL load happened. I guess something work wrong doing the first load... i hope is due to ION and it will work fine on IOS provisioning.
0
James
Top achievements
Rank 1
answered on 10 Jun 2013, 11:51 AM
I am experiencing the same issue here. It works with Android but in Icenium Ion, the OnDeviceReady fires more than once. I wonder if this is normal? If so then we will expect that it will only fire once in actual app from the appstore.

James
0
Steve
Telerik team
answered on 12 Jun 2013, 08:49 AM
Hi guys,

We're not able to reproduce this locally, can you share:
  • what Cordova version does your app target?
  • are you using latest ION, if unsure re-install from App Store.
  • what is your iOS device and OS version?
  • does this happen on any app, for example if you create a brand new Blank app and just add an alert in deviceready - does the problem surface on your end? If it happens on specific app, please share which is your app and we would look into it.

Regards,
Steve
Telerik

Looking for tips & tricks directly from the Icenium team? Check out our blog!
Missed our first webinar, watch it here.
Share feedback and vote for features on our Feedback Portal.
0
Andres
Top achievements
Rank 1
answered on 18 Jun 2013, 11:04 PM
Hi,
i have been trying to reproduce like my app (an initial sql database load) but i cant.

I have 2 js: main and sql.

In main, i call the function app.populateDb(), which is allocated on "sql..js". This function uses local storage.

I move the function to "main.js" and everything works fine.

Maybe sql.js is not ready when calling at first time? i dont really know...

James, let me know if this happend to you.
Tags
AppBuilder companion app
Asked by
Andres
Top achievements
Rank 1
Answers by
Steve
Telerik team
Andres
Top achievements
Rank 1
James
Top achievements
Rank 1
Share this question
or