Archive for the ‘xcode’ Category
Beginning May 1st 2013, apps submitted to the Apple App Store…
Cordova/PhoneGap fulfills requirement (1) since version 2.5.0 and fulfills requirement (2) since version 1.7.0.
But what if my Cordova/PhoneGap app, which I am unwilling to upgrade, needs to be updated and submitted to the App Store?
You will have to manually update and patch your code. It’s not going to be an easy task, and I should warn you that upgrading will be easier. The main changes are to handle the iPhone 5 sized splashscreen, and the code to handle that is only in Cordova/PhoneGap 2.5.0. You can include the iPhone 5 sized asset and this will trigger the app to be the right size, but because of our splashscreen support it needs to match iOS showing the splashscreen after that splashscreen disappears. See our SplashScreen API for more details.
To be doubly sure – select your project icon in the Project Navigator in Xcode, then select the Summary tab. Select your project target then review the App Icons and Launch Images sections – you’ll see if you are missing anything or whether the assets are not the right sizes (denoted by the yellow triangle icon with an exclamation point in it).
With the release of Apache Cordova 2.0.0 there are some significant changes for the iOS platform. We’ve removed the problematic Xcode templates, and updated our support to iOS 4.2 and greater only. Support for ARC (Automatic Reference Counting) was planned but pushed to a later release (tentatively scheduled for 2.1.0).
1. Removal of the Xcode Templates
Initially we had Xcode 3 template support, so when Xcode 4 rolled in, we updated our templates to support Xcode 4. However, because of Xcode 4′s template limitations, this resulted in a poor user experience when first creating a new Cordova-based Application. The Xcode 4 template format is undocumented – we couldn’t add a folder reference nor add a sub-project, so we had to include a pre-built Cordova.framework and also make the developer copy in the www folder manually.
A developer had to:
- Build once to copy in the “www” folder (from the Cordova.framework) into their project folder on disk
- Locate the “www” folder in their project folder on disk
- Drag in the “www” folder to their project icon in Xcode
This was very error-prone and did not lead to a good “first-run” user experience. Shipping a pre-built binary (Cordova.framework) also causes problems for certain systems (unreproducible crashes with Reachability) and problems with the inability to debug errors in the Cordova library itself.
The Xcode templates have been replaced by our new command-line utility to create a new project.
2. Create a new Cordova-based Application project from the command line
Consult this blog post “PhoneGap 2.0 Getting Started” as well for any errors you encounter.
This template creation method eliminates all the problems with the Xcode 4 template. Create the new project, and you are ready to go immediately. Your new project also links in CordovaLib as a sub-project now, so you have access to the Cordova source code for debugging if you need to.
Moving to a command-line interface also allows for greater flexibility in tooling and packaging.
3. Debug, emulate and view the console log of your Cordova project from the command line
When you create a new Cordova-based application project, you will notice that there is a new “cordova” folder included in your project folder. In there, there are three scripts: debug, emulate and log.
Navigate to the cordova folder from Terminal.app, and you can type the appropriate commands to use these scripts. Using these scripts, you will never need to launch Xcode again. Details on what these scripts do are at docs.phonegap.com
4. Support of iOS 4.2 and greater only (and drop iOS 3 support)
5. Xcode 4 and Lion & Mountain Lion support only
Some developers are still using Snow Leopard (10.6) – which only has Xcode 4.2 (iOS 5.0 SDK). With the upcoming release of the iOS 6 SDK, there doesn’t seem to be any Snow Leopard support for it. A SDK release is always coupled with a version of Xcode, and all the newer versions of Xcode are for Lion (10.7) and Mountain Lion (10.8) only. The Apple App Store will only accept apps that are built using the latest version of the iOS SDK. When iOS 6 is released, this will preclude Snow Leopard (10.6).
Currently there is still a GUI based installer that installs CordovaLib into your home folder’s Documents sub-folder, and it also updates the $(CORDOVALIB) Xcode variable. The GUI installer will be removed in a future release, and installation will be through the command-line as well. This will allow us to version and package Cordova iOS through homebrew, for example.
Xcode 4 template specs are undocumented and buggy. So, there are issues:
- We cannot automatically include the “www” folder in the template – the user has to add it in manually (a quick drag and drop). I added in checks and warnings if users try to run the app without adding this in.
- Some files, like .h and the -Info.plist file, are included in the ‘Copy Bundle Resources’ build phase by the template. No biggie during run-time, but for those with OCD they will want to remove these from the Build Phase (if only to get rid of the warning).
- Because Xcode 4 does not expand tildes (~), I cannot add a reference to the PhoneGap.framework in the user’s home folder, so I added it to a shared location /Users/Shared which has r+w permissions for everyone (the common folder /Library/Frameworks needs admin privileges). It was added here so users without admin privileges can still use PhoneGap.framework, and by extension, the Xcode 4 Template.
- beta1 – Initial release
- beta1.1 – Bug fix for issue #81 (moved framework from /Users/Shared/Library to /Users/Shared/PhoneGap)
- beta1.2 – Made /Users/Shared/PhoneGap writable to everyone
- beta1.3 – Fixed Template not copying over the ‘www’ directory from the framework location (happened only for users that only installed beta1.3 and didn’t migrate from an earlier beta version). This version was tested on a clean Mac OS X 10.7 Lion DP3 system running Xcode 4.1 DP5, and works great.
- beta2 – (UPCOMING) add AppleScript in the project Run Script build phase to get Xcode to automatically add the ‘www’ folder for you
UPDATE: PhoneGap 0.9.5.1 includes the Xcode 4 template now, download it from phonegap.com
Currently the PhoneGap installer for iOS does not create an Xcode 4 template. The issue is tracked here.
I’ve created a shell script to create a PhoneGap project from the command line. You will still need PhoneGapLib installed – download the installer from http://phonegap.com and run it first.
Instructions are in the shell script itself (open it up in a text editor). View the script, then File -> Save As… to save it. [For Cordova - replace occurrences of 'PhoneGap' in the value for the path with 'Cordova': https://github.com/apache/incubator-cordova-ios/blob/1.0.0/create_project.sh#L41]
Cameron Perry has a good post about using PhoneGap with Xcode 4 that might solve some problems users might have.
I started writing this shell script because Xcode 4 keeps crashing, so I ended up editing my code in TextMate, and had iTerm open so I can build, then deploy the app automatically in iPhone Simulator.
The script takes three arguments, the first is the name of the project (here the limitation is that it has to be the name of the .xcodeproj and the .app name), and the second is the configuration (Debug/Release – defaults to Debug), and the third is an optional argument, the name of the log file that the log will be written to (defaults to stderror.log).
Also, you will need the latest code of ios-sim. I could have added a step to check whether you have it installed and download, build and install it for you, but maybe next time Make sure you download the latest source, and not one of the packages.
One you download it and build it, copy the ios-sim binary to somewhere in your path – /usr/bin is a good location.
Download the script. It is WTFPL licensed. Run it without arguments to see the help text.
chmod 755 sim-run.sh on the script to give it exec privileges.
The script builds your project, launches the project in the iPhone Simulator, activates the iPhone Simulator (brings it to front), logs the output to a file, and also displays the contents of the logfile as it is written to. On each run, it writes to a fresh log file, and the previous log file is backed up.
Found this useful information, regarding Xcode error reporting for shell build phases. For example, if we were to include JSLint in PhoneGap iPhone, we could format the errors this way below so code where the errors occur are easily editable:
In shell build phases you can write to stderr using the following format:
<filename>:<linenumber>: error | warn | note : <message>\n
It’s the same format gcc uses to show errors. The filename:linenumber part can be omitted. Depending on the mode (error, warn, note), Xcode will show your message with a red or yellow badge.
If you include an absolute file path and a line number (if the error occurred in a file), double clicking the error in the build log lets Xcode open the file and jumps to the line, even if it is not part of the project. Very handy.