PhoneGap build with iOS from the command line

PhoneGap Build download

PhoneGap lets you create mobile apps using web technologies (HTML, CSS, JS) whilst still accessing native device functionality that’s not currently available in the browser. PhoneGap Build is a cloud-based service that generates your app for multiple platforms at once, without you having to set up all the toolchains.

In order to get your app up and running on an iOS device, you need to jump through many hoops in terms of certificates, profiles, etc. It’s possible to set all this up using Xcode and the iOS Provisioning Portal, but this rather obfuscates the process – not to mention depending heavily on a toolchain that is a few GBs to download. It turns out to be possible to do this largely from the command line, too.

There’s a good post in the PhoneGap community on this: Detailed Guide for setting up building iOS apps without a Mac. However, the guide is a year old and written for non-Mac users. Here then, is an updated Mac version. OpenSSL should already be available on the Mac, so we can dive right in.

  1. Create a working directory. Let’s call it Signing. Open a command prompt and move to the Signing directory.

  2. Create a key (change mykey to something more appropriate):

    openssl genrsa -out mykey.key 2048
  3. Create a certificate signing request (change my key, email address, your name, your country). Refer to the SSL Certificate Country Codes to find your country code (note, for example, that UK users need to specify GB and not UK):

    openssl req -new -key mykey.key -out CertificateSigningRequest.certSigningRequest -subj "/emailAddress=email@address.com, CN=Your Name, C=US
  4. Upload the signing request in the Apple iOS Provisioning Portal. Click on Request Certificate, then “Choose File” at the bottom of the page. Select the request file you created in the previous step (CertificateSigningRequest.certSigningRequest), and click Submit. Note that if you already have a certificate listed, you will not see the Request Certificate button – you will need to revoke your previous certificate before you are able to do this.

  5. Refresh the Developer Certificates page and you should see a Download link. Download the file ios_development.cer and save it to the Signing directory.

  6. Convert the binary-encoded certificate .cer to a .pem (Base64 encoded) file:

    openssl x509 -in ios_development.cer -inform DER -out ios_development.pem -outform PEM
  7. Create a .p12 file containing the certificate and private key. Enter a password when asked, you will use this later in PhoneGap build:

    openssl pkcs12 -export -inkey mykey.key -in ios_development.pem -out ios_dist.p12
  8. On the Apple iOS Developer site, set up your device, app ID and provisioning.

    • Devices: click “Add Devices”, then enter the device name (something memorable like “My development iPhone”), and the device id (use the “ad hoc helper” app, Xcode or iTunes to find the id).

    • Apps: click “New App ID”, enter a description, default to Use Team ID, and enter your App ID Suffix (e.g. com.example.helloworld).

    • Provisioning: click “New Profile”, enter a profile name, select your certificate, select your app ID, select your devices, click Submit. If the following page shows “Pending”, wait a few seconds, reload, then click Download. Save the profile to the Signing folder.

  9. Proceed to the PhoneGap build site and upload the .p12 and provisioning files.

  10. Click on Unlock key, enter your certificate password from step 7, and optionally check “Set as your default key”.

  11. Upload your app, build it, and you should see the iOS version successfully built.

You can now do cool things like scan the QR code (using e.g. QRReader) to be prompted to install your app from PhoneGap build.

Problems, errors, omissions, enhancements? Let me know.

 

This entry was posted in Computing, Mobile Tech, Planet, Research and tagged , , , , , . Bookmark the permalink.

8 Responses to PhoneGap build with iOS from the command line