Upgrading to Phonegap 2.0

I recently upgraded my ios app to Phonegap 2.0 and found the upgrade instructions a little daunting. In an attempt to make them more approachable & consumable, I’ve annotated many of them below.

Please let me know if I missed anything.

  1. Install Cordova 2.0.0

    1. Download from http://phonegap.com/download
    2. Unzip the file into ~/pg2.0
    3. Double click on the ~/pg2.0/Cordova-2.0.0.pkg to begin the installation
  2. Create a new project from the command-line tools - you will have to grab the assets from this new project

    1. TEMP_PROJ=~/temp_project2.0
      ~/pg2.0/lib/ios/bin/create $TEMP_PROJ com.temp_project2.0 TempProject
  3. Copy the www/cordova-2.0.0.js file from the new project into your www folder, and delete your *www/cordova-1.9.0.js *file

    1. $EXISTING_1_9_PROJ=~/dev/iphone/myapp/ #Set this to the path of the folder that contains your app’s www folder
      cp $TEMP_PROJ/www/cordova-2.0.0.js $EXISTING_1_9_PROJ/www
  4. Update the Cordova script reference in your www/index.html file (and any other files that contain the script reference) to point to the new cordova-2.0.0.js file

  5. Copy the “cordova” folder from the new project into your project’s root folder (if you want the project command-line tools)

    1. cp -r $TEMP_PROJ/cordova/ $EXISTING_1_9_PROJ/www
  6. Add a new entry under Plugins in your Cordova.plist file (under the Supporting Files group) - the key is Device and the value is CDVDevice

    1. Edit Cordova.plist, to include Device/CDVDevice like so, (or edit the file in Xcode)

      Plugins

      Device CDVDevice Logger
  7. Remove Cordova.framework

    1. Select *Cordova.framework *in Xcode then Edit -> Delete, then select Remove Reference
  8. Remove verify.sh from the Supporting Files group

    1. Select verify.sh in Xcode Select in *Cordova.framework *in Xcode
  9. Select the project icon in the Project Navigator, select your project Target, then select the “Build Settings” tab

  10. Search for “Preprocessor Macros”, then remove all “CORDOVA_FRAMEWORK=1” values

  11. Locate the CordovaLib folder that was installed in your hard-drive under your home folder’s Documents sub-folder.

  12. Locate the CordovaLib.xcodeproj file in the CordovaLib folder, then drag and drop the file into your project - it should appear as a sub-project.

    1. Drop CordovaLib.xcodeprojon top of your project to include to it in as a sub-project
  13. Build your project, you should get some errors relating to #import directives

  14. For the #import errors, change any quote-based imports in this style:

    #import “CDV.h”

    to this brackets-based style:

    #import <Cordova/CDV.h>

    and remove any #ifdef wrappers around any Cordova imports, they are not needed anymore (the imports are unified now)

  15. Build your project again, and it should not have any #import errors.

    1. You will still have build errors, they will get cleaned up shortly
  16. Select the project icon in the Project Navigator, select your project Target, then select the “Build Phases” tab

  17. Expand the “Target Dependencies” phase, then select the “+” button

  18. Select the “CordovaLib” target, then select the “Add” button

  19. Expand the first “Link Binary with Libraries” phase (it should already contain a bunch of frameworks), then select the“+” button

  20. Select the libCordova.a static library, then select the “Add” button

    1. Select libCordova.a from the dialog
    2. When these steps are complete, it should look like the following
  21. Delete the “Run Script” phase.

    1. Click the X to the right of the Run Script section title and confirm deletion
  22. Select the project icon in the Project Navigator, select your project Target, then select the “Build Settings” tab

  23. Search for “Other Linker Flags”, and add the values -all_load and -Obj-C

    1. Modify the flags by clicking the + at the bottom and adding both flags separately
  24. Expand the “CordovaLib” sub-project

  25. Locate the “VERSION” file, drag it into your main project (we want to create a link to it, not a copy)

  26. Select the “Create groups for any added folders” radiobutton, then select the “Finish” button

  27. Select the “VERSION” file that you just dragged in a previous step

  28. Press the key combination Option-Command-1 to show the File Inspector (or menuitem View -> Utilities -> Show FileInspector)

  29. Choose “Relative to CORDOVALIB” in the File Inspector for the drop-down menu for Location

  30. Build your project, it should compile and link with no issues.

  31. Select your project from the Scheme drop-down, and then select “iPhone 5.1 Simulator”

  32. Select the Run button

NOTE 1: If your project is not working as expected in the Simulator, please take a note of any errors in the console log in Xcode for clues. NOTE 2: For the unified #import headers to work, the build products should build into the same build directory. You may need to set the preference “Xcode Preferences -> Locations -> Derived Data -> Advanced…” to “Unique”