Fix problem with deviceready being called before device properties are guaranteed to be set.

This commit is contained in:
Bryce Curtis
2010-09-20 15:39:54 -05:00
parent a59cad68e2
commit ace84227cc
2 changed files with 89 additions and 8 deletions
Regular → Executable
+27 -3
View File
@@ -12,22 +12,46 @@ function Device() {
this.phonegap = null;
var me = this;
PhoneGap.execAsync(
this.getInfo(
function(info) {
me.available = true;
me.platform = info.platform;
me.version = info.version;
me.uuid = info.uuid;
me.phonegap = info.phonegap;
PhoneGap.onPhoneGapInfoReady.fire();
},
function(e) {
me.available = false;
console.log("Error initializing PhoneGap: " + e);
alert("Error initializing PhoneGap: "+e);
},
"Device", "getDeviceInfo", []);
});
}
/**
* Get device info
*
* @param {Function} successCallback The function to call when the heading data is available
* @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
*/
Device.prototype.getInfo = function(successCallback, errorCallback) {
// successCallback required
if (typeof successCallback != "function") {
console.log("Device Error: successCallback is not a function");
return;
}
// errorCallback optional
if (errorCallback && (typeof errorCallback != "function")) {
console.log("Device Error: errorCallback is not a function");
return;
}
// Get info
PhoneGap.execAsync(successCallback, errorCallback, "Device", "getDeviceInfo", []);
};
/*
* This is only for Android.
*