I’m trying to use PhoneGap DatePicker plugin (PhoneGap 1.5 (Cordova) in Xcode 4.2) for iOS. I added the DatePicker.h and DatePicker.m files into Plugins folder and DatePicker.js into www folder. Also, I edited the Cordova.plist file to add a new entry for DatePicker plugin with “DatePicker” as key and “DatePicker” as value. I’m using the following code to show DatePicker
var cb = function(date) {
console.log(date.toString());
document.getElementById("date").innerHTML = date.toString();
}
var show = function(mode) {
plugins.datePicker.show({
date: new Date(),
mode: mode, //date or time or blank for both
allowOldDates: false
}, cb);
}
but it’s not working. Any suggestions?
During phonegap development I used to following approach to determine why a plugin was not working:
For this I use Weinre. Start the weinre server, include the weinre javascript in your page and deploy your application to a device that is in the same (wireless) network or run in on the iOS simulator. (Do not forget to include the weinre server ip address under the ExternalHosts key in the file used to be named Phonegap.plist)
Now when the application is running, have can go to the debug console and inspect the value of window.plugins. You can do this by simply typing
window.pluginsinto the console.If you don’t see the plugin listed, you need to check if the
.mand.hfiles are correctly added to the project. In Xcode it is easy to make a mistake and accidentally include them by reference.If the plugin is available, you can directly try to invoke it using the Weinre remote debug console. You should also get some good feedback in case of any errors.
At this point you usually nailed down the error. If the datepicker is available to phonegap but still it is not behaving correctly, you can now set breakpoints in the
.mfile and run the application in Debug Mode on the iOS simulator from XCode. Now step trace through the plugin code to find out why the native iOS code is not working.