Overview

Objectives

  • generate and download an iOS binary file for testing on an iPhone, or submission to the App Store
  • gain familiarity with various FHC commands i.e. target, login, apps, stage, configuration, account, build

Prerequisites

Optional

  • vmc is installed (for verifying server side elements)

Tutorial

Step 1 - Target setup

If not already done during FHC setup, set the target and log in:
fhc target https://mobilecf.feedhenry.com
fhc login [<email> <password>]

Step 2 - Create app

The App we are going to create is a clone of the App Anatomy tutorial. This app is available from the FeedHenry github page. You need to fork this repository in github and obtain the git read-only url i.e. git://github.com/[username]/App-Anatomy.git. For more info on forking, see here To create the app from your newly forked repo, use the following command:
fhc apps create <app_title> [<git-url> [<git-branch> [<key-file>]]]
e.g.
fhc apps create MyApp git://github.com/feedhenry/App-Anatomy.git
We didn't have to specify the git branch as it defaults to 'master', or specify the key file as we're using a read-only git url. If successful, an App ID will be returned. You can also verify the app was created by executing the following command:
fhc apps
This will return a list of all your apps.

Step 3 - Stage app to CloudFoundry

The FHC command line tool can stage the server side code of your App to CloudFoundry. For a development build we can tell FHC to stage in 'develop' mode i.e. for development use. For a release build we can use 'live' as the mode. The fhc stage command expects the GUID of the app you want to stage (found using fhc apps or by 'Tab completion'), and the staging mode:
fhc stage <app-id> [--<stage_mode>]
e.g. for a development build (Distribution Ad Hoc profile)
fhc stage 3YchpSHVfzgr0NCGBDHoAMfN --develop
or for a release build (Distribution App Store profile)
fhc stage 3YchpSHVfzgr0NCGBDHoAMfN --live
If you have the vmc tool installed, you can verify your app is staged to CloudFoundry by executing the following command:
vmc apps

Step 4 - App Setup

First set the iOS App Id that you have selected in your mobile provisioning profile.
fhc configuration set <app-id> <destination> <property> <value>
e.g.
fhc configuration set 3YchpSHVfzgr0NCGBDHoAMfN iphone "app Id" com.feedhenry.test.appname
Then select the package that should be used for the built application. In App Anatomy, there are 2 main packages in the client folder for adjusting the look and feel: android and iOS. Before we do an iOS build, we can set a configuration property so that the 'iOS' package is used for iOS builds. This can be done using fhc configuration:
fhc configuration set <app-id> <destination> <property> <value>
e.g.
fhc configuration set 3YchpSHVfzgr0NCGBDHoAMfN iphone packages iOS
To verify the property was updated, you can read back properties in a similar way:
fhc configuration list <app-id> [<destination>]
e.g.
fhc configuration list 3YchpSHVfzgr0NCGBDHoAMfN iphone
The 'packages' field should have a value of 'iOS'.

Step 5 - Build App

To generate a build of you app for iPhone, you can use the fhc build command. For iOS development we first need to upload our Distribution certificate (with corresponding private key). The FHC tool can be used to upload these resources . The quickest way to upload these resources is shown here too:
fhc account upload-resource <destination> <file-path> <res-type> <config>
e.g.
fhc account upload-resource iphone ~/dist.p12 certificate distribution
Or if your certificate and key file are separate:
fhc account upload-resource iphone ~/dist.cer certificate distribution
fhc account upload-resource iphone ~/key.p12 privatekey distribution
Now that a Distribution certificate and key are associated with our account, we can issue the build command:
fhc build app=<app-id> destination=<dest> version=<ver> [config=<config> 
keypass=<keypass> certpass=<certpass> provisioning=<provisioning-file>] 
[download=true]
e.g.
fhc build app=3YchpSHVfzgr0NCGBDHoAMfN destination=iphone version=4.0 
config=distribution keypass=mykeypass certpass= provisioning=~/app.profile 
download=true
The keypass argument should match the password set on your uploaded private key. If you have a password on your certificate, you can specify this too. The provisioning argument should point to the either:
  • Distribution Ad Hoc provisioning profile for a development build
  • Distribution App Store provisioning profile for an app store build
When the build is finished, some information about the build task will be shown. If the download argument was set to 'true', the iOS binary file (inside a zip file) should now be in the current directory. Note: to continue this lab, you will need a development build as opposed to an app store build. App store builds cannot be deployed to a device for testing.

Step 6 - Verify Server Side Code

When the app starts up, it makes a call to the server for some configuration data. While executing the code to get this data, there is a console.log() statement for debugging purposes. This code can be found in /cloud/main.js:
exports.getConfig = function(params, callback) {
  console.log('in getConfig with ts:' + Date.now());
  var cfg = require("config.js");
  return callback(null, {
    data: cfg.config
  });
};
We can view the output of console.log() statements using the vmc tool. But before we can do that, we need to install the binary file on an iPhone. Once installed, start the app and wait until it loads. After loading is complete, we can verify that the server side code was called by running the following command:
vmc logs <app-id>
You can obtain the app id by running:
vmc apps
The output of vmc logs should look something like this:
====> logs/stdout.log <====

2012-01-02 10:39:08 INFO Binding to redis: 172.30.48.40:5029
App started at: Thu Feb 02 2012 10:39:08 GMT+0000 (UTC)
in getConfig with ts:1328099976063

What next?