Friday, April 13, 2012

My first Cordova 1.6.0 iOS project: generated by command line

UPDATE: this is no longer relevant, please see the PhoneGap command-line guide for iOS for instructions.

I now have the pleasure to restart my Cordova project based on Cordova 1.6.0. I tried uninstalling Cordova 1.5.0 and then installing Cordova 1.6.0 but my Xcode 4.3.2 decided to use the old template to construct my Cordova project. I got some very nice messages of  built-in "plugins" not being found so I decided to try making my project from the command line.

I found Shazron had already posted  how to create a PhoneGap project from the command line so I made an adaptation (UPDATE: no longer valid) to create a Cordova 1.5/1.6+ project. I am actually very happy with the results since you don't have to drag-and-drop the www folder. You have to make sure you select the right project and target to run the generated project. UPDATE: there will be some ugly log messages in the debug mode so it is better to go into release mode (Apache issue CB-502 has been filed).

Cordova iOS 1.6.0 changed the global Cordova to cordova to be consistent with the Android version, so something like << Cordova ||= cordova; >> has to be added to the Plugin Javascript to work for both Cordova 1.5 and 1.6.

I tried including a couple plugins including an adaptation of the Globalization plugin and chbrody / Cordova-SQLitePlugin and they seemed to be working fine. UPDATE this is no longer valid: Some changes have been checked into https://github.com/chbrody/Cordova-SQLitePlugin/blob/master/Cordova-iOS/Plugins/SQLitePlugin.h, probably due to the different structure generated by create-ios-project.sh.

The next challenge is to run the program on a device. Since the command line did not provide an option to specify the company identifier, simply fix the Bundle identifier on the project summary pane to be like <<MYIDPREFIX.AppName>> and it should work with a wildcard app ID.

Now if you do not want to use the wildcard app identifier you have to go back to the Bundle and take out your ID prefix so the Bundle identifier should be like <<AppName>>. You can also remove your wildcard provisioning profile from the Xcode organizer to make sure it is matching the proper, desired provisioning profile for your app. So the Xcode has stored your ID prefix somewhere, I don't know where but this actually is working for me. If anyone knows how it works please post a comment with a link to a good explanation.