Friday, April 13, 2012

Running an old PhoneGap iPhone plugin on Cordova 1.5+ iOS

I have been thinking about the nightmare of supporting multiple versions of Cordova/PhoneGap and had an idea to make a shim to build and run old PhoneGap plugins on Cordova iOS 1.5+. Of course we want the plugins to migrate to the new Cordova API and abandon the old one but this will not happen overnight.

So far I tried making an Objective-C PGPlugin class, deriving from CDVPlugin in PGPlugin.[hm] so that an old PhoneGap plugin can compile and run. Of course we will need some more definitions to support certain plugins but this was a nice quick and easy test. For a first test I discovered phonegap-plugins / iPhone / Prompt which had not yet been ported to Cordova 1.5+.

I put the PGPlugin.[hm] in the Plugins folder, adding a Javascript file, using the test code in onDeviceReady(), and it worked the first time!

I discovered that the extra Javascript to define window.PhoneGap is not necessary before Cordova 2.0, but I checked it in anyway to be prepared for the future.

So I have a start to run old PhoneGap plugins on Cordova 1.5+. Next is to try some more old PhoneGap plugins, especially ones that are exhibiting more dependencies.

UPDATE: test with the BundleFileReader is working great with a typedef and 2 enum values added to PGPlugin.h.